My text file looks like this:
987 10.50 N 50
383 9.500 N 20
224 12.00 N 40
I want to read only the second column of data. How w
In C++ you could consider using std::istringstream, which requires the include: #include . Something like:
std::ifstream ifs("mydatafile.txt");
std::string line;
while(std::getline(ifs, line)) // read one line from ifs
{
std::istringstream iss(line); // access line as a stream
// we only need the first two columns
int column1;
float column2;
iss >> column1 >> column2; // no need to read further
// do what you will with column2
}
What std::istringstream does is allow you to treat a std::string like an input stream just like a regular file.
The you can use iss >> column1 >> column2 which reads the column data into the vaiables.