becomming angry with chars, strings, text...

Started by
10 comments, last by Rome 20 years, 9 months ago
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.
Advertisement
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]
---------------
Hi there, at a quick glance i can see that you missed a ''<'' in your ''cout''.
An ASCII tetris clone... | AsciiRis
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
______________________________________________________________________________________The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ"So. Any n00bs need some pointers? I have a std::vector<n00b*> right here..." - ZahlmanMySite | Forum FAQ | File Formats______________________________________________________________________________________
I''m mostly angry with ints.
They need to decide whether they''re long or short...

Check out Super Play, the SNES inspired Game Engine: http://www.superplay.info

quote:Original post by Thunder_Hawk
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



Ohh interesting i didnt realize.
An ASCII tetris clone... | AsciiRis
thanks, but it doesn''t display the name in dos when i compile with the cout.
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 Miserable
By the way, it''s <iostream>, not <iostream.h>; search GameDev on the topic and you''ll find lots of reasons why ...
I''ll save everyone the trouble of searching: here''s a good topic on this issue. I have it bookmarked for this purpose.
Ohh my gosh its a horrible de ja vous. ....
Miserable, did you even try to compile that before you posted it?
An ASCII tetris clone... | AsciiRis

This topic is closed to new replies.

Advertisement