I declare a global string and give it a value "ABC" in Function1. When I try to cout it in my main function, it gives error:
Terminate called after throwing an instance of 'std::logic_error' what(): basic_string::_S_construct null not valid
The cout works perfectly fine within the 'Function1' function, but for some reason gives the error in main. I understand it has something to do with the difference between std::string and char*, but I don't know the exact problem. How do I avoid the error?
Let me guess - you followed the "gotta initialise all variables" brigade and actually wrote something like string str = 0;
so trying to set your string to a null pointer.