Using a string in more than one file...
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.
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)
extern string mySring;
before using it.(that, at least, is how to do it in C)
[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;
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;
In file1 you have:
string myString;
and in file2 and every other file you want
to use it in, you have:
extern string myString;
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement