I have a program with multiple functions and they both use a string that is the same. So, I was wondering how do I make a string public? I defined outside my int main and the other function.
By public I assume you mean global, since you have nothing about classes here. Or code for me to base an answer off. Make a variable global by defining it outside of main
You mean a global string? If you are going to use the string from multiple files you can declare the string with extern in the a header file that you can include if you want to use the string externconst std::string GLOBAL_STRING;.
In one of the source files you define the string const std::string GLOBAL_STRING = "Hello World!";.
If you are only using one file you can skip the extern declaration. If you want a mutable string just remove the const keyword.
Well I tried to an example, but I guess it didn't portray my problem. So I have a file with 2 functions which are both int's. I use a string in both (name) where in int main, it gets the user's name and in int battle, it displays it. This gave me the error above