我使用VB已经有一段时间了。现在我给了C++一个机会,我遇到了字符串,我似乎找不到一种方法来声明一个字符串。
例如在VB中:
Dim Something As String = "Some text"或
Dim Something As String = ListBox1.SelectedItem在C++中,上述代码的等价物是什么?
任何帮助都是非常感谢的。
发布于 2012-04-19 06:03:25
C++提供了一个string类,它可以像这样使用:
#include <string>
#include <iostream>
int main() {
std::string Something = "Some text";
std::cout << Something << std::endl;
}发布于 2012-04-19 06:03:14
使用标准<string>标头
std::string Something = "Some Text";http://www.dreamincode.net/forums/topic/42209-c-strings/
发布于 2012-04-19 15:44:55
在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;
}https://stackoverflow.com/questions/10218714
复制相似问题