0

This is my code

#include <iostream>
#include <vector>
#include <string>
#include <fstream>
#include <stdlib.h>
#include <conio.h>
#include <stdio.h>

using namespace std;

int main(){
    string humanNo;
    int computerNo = 0;
    do{
        getline(cin,humanNo);
        computerNo = stoi(humanNo);
    }while(computerNo != 4);
}

I am trying to use stoi, stol to easily convert from string to integer in my CodeBlocks IDE. At first I learned that you have to first enable c++11 in the compiler settings. I enabled it but I am still getting the same error. Does anyone know what might be the problem I am encountering?

I am using MinGW compiler.

Jarod42
  • 203,559
  • 14
  • 181
  • 302
Harshal Carpenter
  • 470
  • 1
  • 9
  • 24
  • 1
    What compiler are you using? – MrEricSir Dec 20 '14 at 02:01
  • 3
    Telling us you're using the CodeBlocks IDE doesn't really help, noone cares what editor you're using, the compiler is what matters. I assume you're using the mingw compiler, in which case these functions are not available – Jonathan Wakely Dec 20 '14 at 02:04
  • CodeBlocks comes packaged with MinGW 4.7.1 by default. You can try something like [nuwen.net](http://nuwen.net/mingw.html) (a 64-bit distro with 4.9.1, see the duplicate below), which I believe the string conversion functions work. –  Dec 20 '14 at 02:05
  • yes minGw. What should I do ? – Harshal Carpenter Dec 20 '14 at 02:06
  • @remyabel I downloaded the MinGW distro and extracted to same folder, same error :( .. please help – Harshal Carpenter Dec 20 '14 at 02:25
  • You could try this patch: http://paste.fedoraproject.org/161510/19042363/raw/ – Jonathan Wakely Dec 20 '14 at 02:26
  • @JonathanWakely Umm I am sorry but how do I use this ? .. I am novice programmer sorry:( – Harshal Carpenter Dec 20 '14 at 02:29
  • OK, find the file `basic_string.h` in the gcc 4.7.1 installation from mingw and replace it with http://paste.fedoraproject.org/161513/4299214/raw/ -- and please comment here to let me know if that works – Jonathan Wakely Dec 20 '14 at 02:41
  • @Harshal I highly doubt that STL's distro is the problem. Try compiling the program using the command prompt, then read your IDE's documentation for using STL's distro instead of the one that comes with the IDE. –  Dec 20 '14 at 02:43
  • @JonathanWakely I already replaced it with 4.9.1 as remyabel said, i changed the basic_string.h, restarted CodeBlocks. Did not work :( – Harshal Carpenter Dec 20 '14 at 02:47
  • @Harshal Did you actually ensure that CodeBlocks is using the correct compiler? The patch should not be necessary for STL's distro. –  Dec 20 '14 at 02:48
  • @remyabel what should i do to ensure that ? thanks – Harshal Carpenter Dec 20 '14 at 02:50
  • @HarshalCarpenter Refer to my previous comment. –  Dec 20 '14 at 02:51
  • @remyabel did not find any documentation or maybe i do not know where it is :( .. but i have only GNU GCC compiler "Detected" when i start the CodeBlocks. – Harshal Carpenter Dec 20 '14 at 03:06
  • Why don't you use Visual Studio? mingw has many bugs, and you are going to encounter more. – Siyuan Ren Dec 20 '14 at 04:15
  • @SiyuanRen Visual Studio is very heavy with those additional graphics, I am using Orwell Dev C++ now. It is supporting C++11 and working just fine.. but I am looking forward to download and setup VS in coming months. Thanks for advice :) – Harshal Carpenter Dec 20 '14 at 04:39
  • @SiyuanRen, Visual C++ has many bugs too – Jonathan Wakely Dec 22 '14 at 15:18

1 Answers1

0

I was not able to fix CodeBlocks for C++11 support, but I downloaded Orwell Dev C++ and followed the instructions over here on stackoverflow. I recommend to everyone to switch to it as it will save you from lot of headache. Thank you all.

Edit: If the CodeBlocks is not working out for you guys. :)

Community
  • 1
  • 1
Harshal Carpenter
  • 470
  • 1
  • 9
  • 24
  • 1
    Actually, Code Blocks works just fine. You're just inexperienced - this isn't so much criticism (everyone has to start somehwere), just a friendly reminder you probably shouldn't hand out advice until you get a much more sure footing than you have right now. – Cubic Dec 20 '14 at 07:40
  • 1
    @Cubic In my case it didn't work out with the advices given by people, I still use codeblocks.. Just wasn't able to setup for C++11.. – Harshal Carpenter Dec 20 '14 at 10:11