0
How to Declare string Variable?
How Do I Declare a string or text type variable?
2 Answers
+ 11
string some_var;
// then do dank stuff to the string, e.g.
cin >> some_var;
// or if you want to get the whole sentence including whitespaces,
getline(cin, some_var);
+ 1
Hi Soumik,
you need to include strings by
#include<string>
than you can use
std::string str = âhello worldâ;
to declare a string variable named str.
(If you use âusing namespace std;â, declaration is like
string str = âhello worldâ;
)