編輯:我試圖通過單擊「有g ++遵循C++ 11 ISO C++語言標準」在C++ 11中使用C++ 11編譯器標誌。Stoi未在範圍內聲明 - Code :: blocks
我得到的stoi沒有在範圍內聲明,我已經添加了C++ 11到Code::Blocks;
我已經在設置 - >編譯器 - >編譯器標誌中添加了兼容性,但它仍然不斷給我這個錯誤。
,當我嘗試做的atoi或者strtol將出現以下錯誤:
C:\Users\user\Desktop\Programming\NewProject\main.cpp|19|error: cannot convert 'std::string {aka std::basic_string}' to 'const char*' for argument '1' to 'long int strtol(const char*, char**, int)'|
我的代碼:
#include <iostream>
#include <vector>
#include <string>
#include <fstream>
#include <cstdlib>
using namespace std;
int main()
{
string numberGuessed;
int numberGuessedint = 0;
do {
cout << "Guess a number between 1 and 10: ";
getline(cin, numberGuessed);
numberGuessedint = stoi(numberGuessed);
cout << numberGuessedint << endl;
} while(numberGuessedint != 4);
cout << "You win!" << endl;
return 0;
}
哪個編譯器?你調用編譯器的實際命令行是什麼? (它看起來像stoi沒有正確啓用)。 –
您是否告訴編譯器使用C++ 11或更高版本?根據[cppreference.com](http://en.cppreference.com/w/cpp/string/basic_string/stol),「stoi」是一個C++ 11功能。 –
我下載了內置minGW的Code :: Blocks。我試圖通過在編譯器標誌中單擊「Have g ++遵循C++ 11 ISO C++語言標準」來告訴它使用C++ 11。 –