gpt4 book ai didi

c++ - 字符串类型是头文件还是标准命名空间?

转载 作者:行者123 更新时间:2023-12-04 17:00:56 24 4
gpt4 key购买 nike

我是 C++ 的新手,大部分时间都在编程,几天前才开始学习,对此我有点困惑。
字符串变量类型是否在标准命名空间中?
我发现我可以使用字符串而不使用 #include <string> .我也可以用 using namespace std; , 激活字符串的使用,或 std::string mystring;例如。
我知道使用 using namespace std;允许使用标准命名空间内的所有命令/函数,即 cout .
如果字符串在标准命名空间内,则为 #include <string>同理using std::string; ?

最佳答案

std::string是在标准库头文件 <string> 中定义的类.与标准库的所有名称一样,它在命名空间 std 中声明。 .

is #include <string> the same as saying using std::string; ?


不,它们有两种完全不同的含义。 #include <string>表示“将标题 <string> 的内容包含到此文件中”。标题包含类的定义 std::string除其他事项外。 using std::string;本质上意味着“在当前命名空间中将标识符 string 声明为 std::string 的类型别名”。

关于c++ - 字符串类型是头文件还是标准命名空间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68156032/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com