首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >C++字符串声明

C++字符串声明
EN

Stack Overflow用户
提问于 2012-04-19 06:01:38
回答 4查看 173.6K关注 0票数 14

我使用VB已经有一段时间了。现在我给了C++一个机会,我遇到了字符串,我似乎找不到一种方法来声明一个字符串。

例如在VB中:

代码语言:javascript
复制
Dim Something As String = "Some text"

代码语言:javascript
复制
Dim Something As String = ListBox1.SelectedItem

在C++中,上述代码的等价物是什么?

任何帮助都是非常感谢的。

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2012-04-19 06:03:25

C++提供了一个string类,它可以像这样使用:

代码语言:javascript
复制
#include <string>
#include <iostream>

int main() {
    std::string Something = "Some text";
    std::cout << Something << std::endl;
}
票数 28
EN

Stack Overflow用户

发布于 2012-04-19 06:03:14

使用标准<string>标头

代码语言:javascript
复制
std::string Something = "Some Text";

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

票数 2
EN

Stack Overflow用户

发布于 2012-04-19 15:44:55

在C++中,您可以像这样声明一个字符串:

代码语言:javascript
复制
#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
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10218714

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档