[英]reading string in c++
在Dev C++
編譯器中,我可以編寫並成功編譯它:
#include <iostream>
#include <string>
using namespace std;
int main ()
{
string method;
cin >> method;
return 0;
}
但是當我在Visual Studio 2013 (console app mode)
編寫上述代碼時,我收到此錯誤:
Error: no operator ">>" matches these operands
operand types are: std::istream >> std::string
在Visual Studio
:
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
string method;
cin >> method;
return 0;
}
我明白錯誤告訴我的是什么。 但為什么只在Visual Studio 2013
?
嘗試在其他標題之前放置標題“stdafx.h”。
#include "stdafx.h"
Visual Studio中讀取字符串的簡單例子:
#include "stdafx.h"
#include<iostream>
#include<string>
#include<conio.h>
using namespace std;
int main()
{
std::string str ;
getline(cin, str);
cout << str;
_ getch();
return 0;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.