Reading data from a text file into varia
Reading data from a text file into variables and arrays
Aug 16, 2014 at 6:05pm UTC
Hi, I'm trying to read a text file and store the data into some variables and arrays.
Here is an example of the data:
param T := 3 ;
param alpha :=
param r :=
What I need to do is to store the number 3 into my T integer, store ones into my alpha array, and store the numers in the second column of r in my r array.
I know I need the following:
ofstream myfile; myfile.open(
//What should go here?
How can I parse the file so that I ignore the unneeded text (like "param T:="), and store only the needed text (like "3")? Thanks.
Aug 16, 2014 at 6:33pm UTC
You can load the file into a stringstream for easier manipulation. Also, you could check every read character, whether its in the range of 0 to 9.
Registered users can post here.
Sign in or register
General C++ Programming
© cplusplus.com, 2000-2014 - All rights reserved -
Spotted an error? contact us