Read set of coordiantes

Jan 28, 2016 at 2:41am
Hi,

I have an input file like this

------------
A 1 B 2 C 3

A 2 B 3 C 4

-------------

I want to read the input file into a 2*3 array and eliminate the A,B,C just like this

[1][2][3]
[2][3][4]


How can I do this?

Thanks
Jan 28, 2016 at 4:04am
Assuming that each element in the input file separated by whitespaces, you can just do this:
1
2
3
4
5
std::ifstream input("input.txt");
char c;
int arr[3];
// stops reading each element after a whitespace
input >> c >> arr[0] >> c >> arr[1] >> c >> arr[2];


- Exactly the same as you would with std::cin.
1
2
3
4
std::cout << "Enter an expression:\n";
char op;
int x, y;
std::cin >> x >> op >> y;
Last edited on Jan 29, 2016 at 5:44am
Jan 29, 2016 at 1:34am
Thanks!
Topic archived. No new replies allowed.