I'm trying to convert a string to an integer and store it in the same variable multiple time through a loop. For some reason it never works after the first time, it screws the number up.
#include <stdlib.h>
#include <string>
#include <iostream>
#include <cstdio>
#include <sstream>
using namespace std;
int main(int argc, char *arg[]){
string test("329034023");
long testNum = 0;
for(int i =0; i < 2; i++){
testNum = 0;
testNum = atoi(test.c_str());
cout<<"number "<<test<<" is: "<<testNum<<endl;
test="23423423423";
}
return 0;
}
any suggestions? I also tried using the istringstream but had the same results.