我一直在使用VB一段时间。现在我给C++一个镜头,我遇到了字符串,我似乎找不到一种方法来声明一个字符串。C++字符串声明
例如在VB:
Dim Something As String = "Some text"
或者
Dim Something As String = ListBox1.SelectedItem
请告诉我等价于C++上面的代码?
任何帮助表示赞赏。
我一直在使用VB一段时间。现在我给C++一个镜头,我遇到了字符串,我似乎找不到一种方法来声明一个字符串。C++字符串声明
例如在VB:
Dim Something As String = "Some text"
或者
Dim Something As String = ListBox1.SelectedItem
请告诉我等价于C++上面的代码?
任何帮助表示赞赏。
C++供给string
类,它可以像这样使用:
#include <string>
#include <iostream>
int main() {
std::string Something = "Some text";
std::cout << Something << std::endl;
}
使用标准<string>
头
std::string Something = "Some Text";
在C++中,你可以声明这样的字符串:
#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;
}
嘿!什么字符。数组? char str [30]; – 2018-02-14 07:31:45