繁体   English   中英

C ++字符串声明

[英]C++ String Declaring

我一直在用VB工作一段时间。 现在我给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";

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

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

C ++中的首选字符串类型是string ,在名称空间std定义,在头文件<string> ,您可以像这样初始化它,例如:

#include <string>

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

更多关于它你可以在这里这里找到。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM