how in C++ would you go about parsing text files.
Printable View
how in C++ would you go about parsing text files.
It depends on the format of the text file. What do you want to do? Read something like a .ini file (pairs of identifiers/values), make a scripting langauge? Read straight data?
My guess is that in C you would use pointers or indexes into arrays, while in C++ you would use iterators and generic containers.
What is parsing?
(no I don't know what parsing means, shoot me)
!bang!
What I need to do is parse a text file for commands.
example:
MakeWin("Window Title Goes Here", left, top, 100,100)
and I need these commands to run in my main program.
I have these functions in my program I just need to get the commands from the file to implement them.
void MakeWin(char *WindowTitle, int x, int y, int xx, int yy);
is how I declared the function and then I have a library that has that function within it, that I have written.
I am making a multitasking gui app for dos that I uses my own custom commands for both drawing and getting mouse clicks, etc.
The only way I have found to multitask is to execute scripts rather than .exe files.
Code:[File.txt]
Window Title ;self explanitory
100 ;x
100 ;y
100 ;width
100 ;height
I dont know if you can get ints with getline() so i just stored them in a char then atoi'd them :)Code:[Part of File.cpp]
char WindowTitle[100];
char x[4], y[4], width[4], height[4];
int ix, iy, iwidth, iheight;
ifstream fileload("File.txt");
fileload.getline(WindowTitle, 100, ';');
fileload.getline(x, 4, ';');
fileload.getline(y, 4, ';');
fileload.getline(width, 4, ';');
ix = atoi(x);
iy = atoi(y);
iwidth = atoi(width);
iheight = atoi(height);
MakeWin(WindowTitle, ix, iy, iwidth, iheight);
Thanks much okismokie, um
is there a way to keep the command and the variables on the same line like the cpp compilers do.