字符串的数据类型是什么? [英] What is the data type for a string?

查看:497
本文介绍了字符串的数据类型是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这很可能是一个非常愚蠢的问题,但在C ++中,字符串的数据类型是什么?我想让变量x =Slim Shady。

This is most likely a very stupid question, but in C++, what is the data type for a string? I want to make the variable x = "Slim Shady".

我要将x声明为int吗?我试着声明它作为一个字符,但当我cout变量,它只给出第一个字母。

Would I declare x as an int? I have tried declaring it as a char, but when I cout the variable, it only gives the first letter. Any help would be appreciated.

推荐答案

您需要包含头文件字符串

You need to include the header file string

#include <string>

然后你就可以使用std :: string

Then you will be able to use std::string

std::string x="Slim Shady"

http://en.cppreference.com/w/cpp/string/basic_string

你也不能使用std :: strings,如果你不想使用它们,虽然他们是你最好的选择

You can also not use std::strings, if you dont want to use them althought they are your best option

您可以使用Char数组或字符指针(C字符串)

You can use Char arrays or char pointer (C-strings)

char x[]="Slim Shady";

char* x="Slim Shady";

auto关键字是一个C ++ 0x功能。你应该远离它,直到你学习C ++基础

The auto keyword is a C++0x feature. You should stay away from it till you learn the C++ basics

这篇关于字符串的数据类型是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆