我是 C++ 的初学者,我正在做 Stroustrup 的Programming Principles And Practice Using C++
中的练习之一。
这个练习要我试验合法和非法的名字。
void illegal_names()
{
// the compiler complains about these which made sense:
// int double =0;
// int if =0;
// int void = 0;
// int int = 0;
// int while =0;
// string int = "hello";
//
// however, this is legal and it runs without a problem:
double string = 0.0;
cout << string<< endl;
}
我的问题是,是什么让 string
与任何其他类型不同?是否有其他特殊类型,如 string
?
最佳答案
所有这些其他名称都是 C++ 语言中的保留字。但是“字符串”不是。尽管 string
是一种常用的数据类型,但它是由更基本的类型构建而成,并在本身用 C++ 编写的库中定义。
关于c++ - 为什么可以使用 'string' 作为变量名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25222095/