Archived

This topic is now archived and is closed to further replies.

Rome

becomming angry with chars, strings, text...

Recommended Posts

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<

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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

}

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
quote:
Original post by Tiffany Smith
Ohh my gosh its a horrible de ja vous. ....
Miserable, did you even try to compile that before you posted it?

No. Honestly, I didn''t really look at the code; I just quoted the OP''s code and modified the sections dealing with strings ...

Share this post


Link to post
Share on other sites