Jump to content
  • Advertisement

Archived

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

Rome

becomming angry with chars, strings, text...

This topic is 5495 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
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]

Share this post


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

Share this post


Link to post
Share on other sites
I''m mostly angry with ints.
They need to decide whether they''re long or short...

Share this post


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

Share this post


Link to post
Share on other sites
thanks, but it doesn''t display the name in dos when i compile with the cout.

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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!