How do you read multiple inputs from a text file?

For my program i need to read three different things per line, the format of the .txt file is:
Fe B 2
O Xe 0
Al Ca 3

I need to read the three values from each line into three variables and then process those variables through some if statements.

So for example, line 1 i need to read 'Fe' as the first string and then skip the whitespace and read 'B' as the next string then thirdly skip the next whitespace and read '2' as a type int.

That's my only problem so if i can get a way to read the three values into different variables and ignore the whitespace then i know how to do the rest.

Thanks to whoever helps me out.
It would help to know what language you are using C or C++.

For C++ look up the iostream functions like cin. For C look at functions like scanf().
using c++ sorry.
closed account (10oTURfi)
1
2
3
4
5
6
7
8
9
10
#include <fstream>

//...
std::ifstream i("myfile.txt");
std::string a, b;
int c;
while(i >> a >> b >> c) // This will read untill end of file
{
//do stuff
}
Topic archived. No new replies allowed.