|
发表于 2003-11-4 12:13:03
|
显示全部楼层
Re: a question of c++
[quote:0b83790a0c="MagicBoy"]this is a c++ program.
#include <iostream.h>
class Hello{
public:
char *s;
Hello(){
strcmp(s,"hello,worls");
}
void Hello::print(){
cout << s << endl;
}
};
int main()
{
Hello *p;
p -> print();
}
but the result isn't view.
why??? :-([/quote]
[code:1]
#include <iostream> // try to use the c++ standard
using namespace std; // if you avoid this line you can always
// replace cout with std::cout.
class Hello{
public:
char s[20];
Hello(){
// strcmp(s,"hello,worls"); ??? strcmp? compare the two string?
strcpy(s,"hello world!");
}
void print();
};
// separate the class defination and class functions is a good idea.
// indeed you should put them in separate files.(.hpp and .cpp)
void Hello::print(){
cout << s << endl;
}
int main()
{
Hello *p,a;
p=&a;
p -> print();
}[/code:1][/code] |
|