becomming angry with chars, strings, text...
hello i''m wondering how to store a large amount of text. i''ve tried from chars to strings to whatever and it never works. especially with a class system.
#include <iostream.h>
#include <conio.h>
#include <string.h>
class player
{
public:
char name[60];
private:
};
void main()
{
player player2;
player2.name = "blah, a really long name that can go on for 60 letters";
cout<<player2.playername;
getch();
}
I just want to know why it won''t save it and work when i run it, thanks.
You'll have to change the player.name="string" to:
strcpy(player2.name, "blah, a really long name that can go on for 60 letters");
Oh yeah, and here's a good page for C Strings (String.h)
http://www.cplusplus.com/ref/cstring/
[edited by - Joe-Bob on July 3, 2003 7:30:33 PM]
strcpy(player2.name, "blah, a really long name that can go on for 60 letters");
Oh yeah, and here's a good page for C Strings (String.h)
http://www.cplusplus.com/ref/cstring/
[edited by - Joe-Bob on July 3, 2003 7:30:33 PM]
quote:Original post by Tiffany Smith
Hi there, at a quick glance i can see that you missed a ''<'' in your ''cout''.
Not quite...Ahem...HTML
quote:Original post by Thunder_Hawkquote:Original post by Tiffany Smith
Hi there, at a quick glance i can see that you missed a ''<'' in your ''cout''.
Not quite...Ahem...HTML
Ohh interesting i didnt realize.
Use proper C++ strings, not character arrays. By the way, it''s <iostream>, not <iostream.h>; search GameDev on the topic and you''ll find lots of reasons why ...
#include <iostream>#include <conio.h>// Different file. <string.h> becomes// <cstring>!#include <string>class player{public: std::string name;private:};// main() -must- return an int!int main(){ using namespace std; player player2; player2.name = "blah, a really long name that can go on for 60 letters - or as many as you want; the std::string will reisze itself"; cout << player2.playername << endl; getch(); // Don''t need to -explicitly- return; main() will // implicitly return 0 unless you specify otherwise}
quote:Original post by MiserableI''ll save everyone the trouble of searching: here''s a good topic on this issue. I have it bookmarked for this purpose.
By the way, it''s <iostream>, not <iostream.h>; search GameDev on the topic and you''ll find lots of reasons why ...
Ohh my gosh its a horrible de ja vous. ....
Miserable, did you even try to compile that before you posted it?
Miserable, did you even try to compile that before you posted it?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement