Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/144.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 为什么我能';你不用绳子吗?_C++_String_Cin - Fatal编程技术网

C++ 为什么我能';你不用绳子吗?

C++ 为什么我能';你不用绳子吗?,c++,string,cin,C++,String,Cin,我有下面的代码 #include <iostream> #include <string> main(){ std::cout << "What's Your Name? "; string x = ""; std::cin >> x; std::cout << std::endl << "Nice to meet you " << x << "!" <<

我有下面的代码

#include <iostream>
#include <string>

main(){
    std::cout << "What's Your Name? ";
    string x = "";
    std::cin >> x;
    std::cout << std::endl << "Nice to meet you " << x << "!" << std::endl;
}
#包括
#包括
main(){
std::cout>x;

std::cout必须指定名称空间:将
string
更改为
std::string

std::string
string
侧注:它是
int main()
,基本
main()
适用于这样的小型项目,您可以在包含后立即使用命名空间std;
执行
操作。看起来您遵循的是一个古老的教程,需要从本世纪升级到其他版本。答案在错误消息中:“注:建议的备选方案:…'std::string'”另外,这是因为 String 在本机C++中不存在,只能在<代码> <代码>中定义,因为它位于 STD< /Cord>命名空间中,所以必须编写STD::String而不是String。或者使用一个定义:<代码>定义字符串STD::String …或者你可以使用“代码>使用STD::String ”我从未见过C++中的但是你知道的更多……THX不要忘记@ BJSistad,你也应该写“代码> int”()/Cord>不仅仅是Maple,它被认为是坏代码。
Running /home/ubuntu/workspace/client.cpp
/home/ubuntu/workspace/client.cpp: In function ‘int main()’:
/home/ubuntu/workspace/client.cpp:6:5: error: ‘string’ was not declared in this scope
     string x = "";
     ^
/home/ubuntu/workspace/client.cpp:6:5: note: suggested alternative:
In file included from /usr/include/c++/4.8/iosfwd:39:0,
                 from /usr/include/c++/4.8/ios:38,
                 from /usr/include/c++/4.8/ostream:38,
                 from /usr/include/c++/4.8/iostream:39,
                 from /home/ubuntu/workspace/client.cpp:1:
/usr/include/c++/4.8/bits/stringfwd.h:62:33: note:   ‘std::string’
   typedef basic_string<char>    string;   
                                 ^
/home/ubuntu/workspace/client.cpp:6:12: error: expected ‘;’ before ‘x’
     string x = "";
            ^
/home/ubuntu/workspace/client.cpp:7:17: error: ‘x’ was not declared in this scope
     std::cin >> x;
                 ^