I was writing a C++ program to manipulate a text file. A part of the task involves searching the text file for a particular "search string" and store a part of it as an integer array.
I wrote the following code:
ifstream myoutfile;
myoutfile.open (outputfile.c_str()); // filename is passed as a user input
string search="SEARCH STRING" // search string
while (getline(myoutfile, line))
{
if (line.find(search) != string::npos)
{
cout << line[54] << line[55] << line[56] << endl;
}
}
the thing is I want to read 54th 55th and 56th characters of the line into an array as a single integer. (Lets say that 54th charcter is '1' 55th is '2' and 56th is '6'. I would like to read it as number 126 into an array. Is it possible to do that inside this loop, or I have to save this into a file and write a separate section to read contents of the file into array. I was wondering whether anybody can help.