0
How to Declare string Variable?
How Do I Declare a string or text type variable?
2 odpowiedzi
+ 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“;
)