-
Adding Basic Controls
Sorry, but I'm a newby to C++, and I'm still trying to get a grip on the language.
I'm using Dev-C++.
I already have the code for creating a Window (Form), but now I need code to create the following.
Menu Items
RichTextbox or a plain old TextBox.
Command Buttons.
-
Learn the language. Then learn Windows programming.
Trust me ;)
-
:(
But I just want to make a basic text editor, and learn how everything works from there. :)
What can I do instead then?
Make console programs?
-
While I'm here, what does cout mean? I know it lets your print text in a console app... also, do I have to end it with endl; ??
Thanks in Advance.
-
cout is a stream (look up iostreams in a C++ reference), attached to the "standard output" (normally prints to the terminal, but can be redirected to a file).
The << operator is overloaded to mean "insert this into the stream":puts "Hello" into the stream. However, that probably won't do much because of buffering, so we have endl, which first puts a newline, then flushes the output buffer to ensure it gets displayed. You should usually just use '\n' unless it *has* to be displayed right then, because it can be inefficient.
-
The reason you shouldn't make a text editor and learn from there is that learning both C++ and the windows API at the same time will most likely be too much for you, unless you are an extremly fast learner.
cout is actually an instance of the class template basic_ostream<char, char_traits<char> >
-
Yeah... but... :(
What can I do instead then?
I've been screwing around with some maths functions, but thats about it...
-
Whats wrong with this??
Code:
#include <iostream.h>
#include <stdio.h>
#include <stdlib.h>
// Demonstrates declaration of a class and
// definition of an object of the class,
// for cout
class Programmer // declare the class object
{
public: // members which follow are public
int itsAge;
int SkillLevel;
void Joke();
};
void Programmer::Joke()
{
cout << "Joke.\n";
}
void main()
{
Programmer Pc_Madness;
Pc_Madness.itsAge = 16;
Pc_Madness.SkillLevel = 1;
// assign to the member variable
cout << "Pc_Madness is " ;
cout << Pc_Madness.itsAge << " years old.\n";
cout << "Pc_Madness's skill level is " ;
Pc_Madness.Joke();
cout << "asdasdasd" ;
getchar ();
return 0;
}
I'm having trouble getting the Pc_Madness.Joke bit to work...
-
Code:
#include <iostream.h>
#include <stdio.h>
class Programmer
{
public:
int itsAge;
int SkillLevel;
void Joke();
};
void Programmer::Joke()
{
cout << "Only Joking :).\n";
}
void main()
{
Programmer Pc_Madness;
Pc_Madness.itsAge = 16;
Pc_Madness.SkillLevel = 10;
cout << "Pc_Madness is " ;
cout << Pc_Madness.itsAge << " years old.\n" ;
cout << "Pc_Madness's skill level is " ;
cout << Pc_Madness.SkillLevel << " / 10 " << endl;
Pc_Madness.Joke();
getchar ();
return 0;
}
:D
Cool
-
You are using the old style headers. For ANSI compatibility and in order to ensure youa apps will compile on future compilers use the new style headers that don't have a .h:
#include <iostream>
#include <cstdio>
using namespace std;
The C++ headers have the same name without the .h ending (iostream.h -> iostream). The C headers have the name prefixed with c and without the .h (stdio.h -> cstdio).
Not all C headers are wrapped this way. In case there is no wrapper you must still use the old style. (e.g. conio.h).
Headers that don't belong to the standard library never have wrappers (e.g. windows.h), except someone writes one (parksie once wrote a windows header, don't know if he finished it).