C 字符串声明

新手上路,请多包涵

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

例如在 VB 中:

 Dim Something As String = "Some text"

或者

Dim Something As String = ListBox1.SelectedItem

什么相当于上面的 C++ 代码?

任何帮助表示赞赏。

原文由 NetInfo 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 720
2 个回答

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

 #include <string>
#include <iostream>

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

原文由 Sergey Kalinichenko 发布,翻译遵循 CC BY-SA 3.0 许可协议

在 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;
}

原文由 argue2000 发布,翻译遵循 CC BY-SA 3.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题