簡體   English   中英

用c ++讀取字符串

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM