• Advertisement

Archived

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

Using a string in more than one file...

This topic is 5304 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

I''ve got a string "string myString;" that need to use in more files than just one. How would I do this? myString will be defined by the user like a name...and I''ll need to use the name in different CPP files.

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
Define Mystring in one file as a global variable. To use it in other files, make sure to define it with:
extern string mySring;
before using it.(that, at least, is how to do it in C)

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Edit:
use:
extern string mySring;
in each file that you need to use it.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
What is not working?
compile error?
runtime error?
maybe a snippet of your code?

Share this post


Link to post
Share on other sites

[Warning] `myString'' initialized and declared `extern''

It''s just a string...and I try to use it in another file and thats the error I get.

extern string myString;

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Just to make sure.

In file1 you have:

string myString;

and in file2 and every other file you want
to use it in, you have:

extern string myString;

Share this post


Link to post
Share on other sites

  • Advertisement