C ++ string declaration

I have been working with VB for some time. Now I give C ++ a shot, I came across strings, I cannot find a way to declare a string.

For example, in VB:

Dim Something As String = "Some text" 

or

 Dim Something As String = ListBox1.SelectedItem 

What is equivalent to the above code in C ++?

Any help is appreciated.

+7
source share
4 answers

C ++ provides a string class that can be used as follows:

 #include <string> #include <iostream> int main() { std::string Something = "Some text"; std::cout << Something << std::endl; } 
+17
source

using the standard <string> header

 std::string Something = "Some Text"; 

http://www.dreamincode.net/forums/topic/42209-c-strings/

+2
source

In C ++, you can declare a string as follows:

 #include <string> using namespace std; int main() { string str1("argue2000"); //define a string and Initialize str1 with "argue2000" string str2 = "argue2000"; // define a string and assign str2 with "argue2000" string str3; //just declare a string, it has no value return 1; } 
+2
source

The preferred string type in C ++ is string , defined in the std , in the <string> header, and you can initialize it as follows:

 #include <string> int main() { std::string str1("Some text"); std::string str2 = "Some text"; } 

You can find more about this here and here .

+1
source