Read file (Extract string by spacing)

I read through the guide but i still can't figure out how to extract a string separated by spacing from a file .

Eg txt file:

Line No: G-code: X-coordinate: Y-coordinate:

N00002 G00 X0009.500 Y0005.000;
N00003 G03 X0002.500 Y0005.000 I-0003.500 J0000.000;
N00004 G03 X0009.500 Y0005.000 I0003.500 J0000.000;


How can i extract string like G00 and G03 which are separated by a spacing? I wish to extract string which are separated by spacing.
You can use operator>>
http://www.cplusplus.com/reference/iostream/istream/operator%3E%3E/
1
2
3
4
5
6
7
8
9
10
11
#include <string>
#include <fstream>

// ...

std::ifstream ifs("myfile.txt");

std::string word;

// extract one word ignoring leading spaces and stopping at the next space
ifs >> word; 
Last edited on
Topic archived. No new replies allowed.