How to Declare a String in C++
- 1). Add the std namespace with the "using" keyword. For example, type:
using namespace std; - 2). Declare a string, optionally using a constructor to assign a starting value. For example, type:
using namespace std;
string example_string;
string constructor_string("This is the string's text."); - 3). Assign values to strings as you would other variables. Strings can be added to each other and assigned using the normal +, = and += operators.
using namespace std;
string example_string;
string constructor_string("This is the string's text.");
example_string = "This is the string's assigned value.";
example_string += " This text was added to the string's original value."