I'm practicing my C++ by coding simple input/ouput from user. I have now been searching for over an hour on how to convert a string to an int. Every answer is different, and require something else.
I'm using Code::Blocks v.13.12. MingW32 folder is added to environment variables. I ended up using stoi to convert my string to integer with try/catch block. I've added C++11 support in Code::Blocks by going to Settings -> Compiler and tick Have g++ follow the C++11 ISO language standard [-std=c++11]. It compiles and runs fine in CB, but when I'm trying to compile manually in the command line i get this error:
error: 'stoi' was not declared in this scope. The line it is refering to: characters = stoi(input);
Thise are the commands I've tried so far: g++ -std=c++11 main.cpp & g++ -std=c++11 -c main.cpp -o main.o & mingw32-g++ -std=c+11 -c main.cpp -o main.o (which is what CB is using according to the output log)
If you have e better example than stoi(), please do make it simple, and add full text of try/catch.
EDIT: This is written at the top of my file:
#include <iostream>
#include <stdlib.h>
#include <time.h>
#include <string>
#include <algorithm>
#include <stdexcept>
using namespace std;
Error message refers to:
int player;
string input;
cin >> input;
player = stoi(input)
Aucun commentaire:
Enregistrer un commentaire