I have a line currentLine = "12 23 45"
I need to extract 12, 23, 45 from this line without using Boost libraries. Since I am using string, strtok does not work for me. I tried a number of things that still do not succeed.
Here is my last attempt
while(!inputFile.eof()) while(getline(inputFile,currentLine)) { int countVar=0; int inputArray[10]; char* tokStr; tokStr=(char*)strtok(currentLine.c_str()," "); while(tokstr!=NULL) { inputArray[countVar]=(int)tokstr; countVar++; tokstr=strtok(NULL," "); } } }
one who does not have strtok
string currentLine; while(!inputFile.eof()) while(getline(inputFile,currentLine)) { cout<<atoi(currentLine.c_str())<<" "<<endl; int b=0,c=0; for(int i=1;i<currentLine.length();i++) { bool lockOpen=false; if((currentLine[i]==' ') && (lockOpen==false)) { b=i; lockOpen=true; continue; } if((currentLine[i]==' ') && (lockOpen==true)) { c=i; break; } } cout<<b<<"b is"<<" "<<c; }
source share