나는 아래의 코드문자열을 사용할 수없는 이유는 무엇입니까?
#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;
}
이 그리고이 오류
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;
^
이유는 문자열을 사용할 수 아니다는 무엇입니까? 나는 Cloud9로 실행 중이며 C++에 비교적 익숙하지 않다. cin
의 입력을 x
문자열로 전송하려면 어떻게해야합니까?
'표준에 변화
string
을 ::' – jaggedSpire사이드 메모를 string'하지 string' : 그것은'INT 주()의'베어 뼈가'주()가'병 [입니다 (http://stackoverflow.com/questions/331148/does-c-allow-default-return-types-for-functions) – dhke
이런 작은 프로젝트의 경우,'namespace std;'권한을 사용할 수 있습니다. 포함 후에. – sp2danny