0

How to Declare string Variable?

How Do I Declare a string or text type variable?

25th Apr 2017, 2:39 PM
Soumik
2 Respostas
+ 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);
25th Apr 2017, 2:54 PM
Hatsy Rei
Hatsy Rei - avatar
+ 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“; )
25th Apr 2017, 2:47 PM
needmorechocolate
needmorechocolate - avatar