Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

newbie fstream question

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I have a file called file.txt and I it contains the following text:

2 22 34 32
23 12 14 11
22 45 65 76
3 4 55 64 12

I want to be able to read each number from each line...How would I read each NUMBER ( which are each seperated by spaces)? All I can figure out if to read the whole line, but I can't figure out how to read each number seperately...thanks..
 
#include<vector>
#include<fstream>
using namespace std;
struct xxx
{
int x[4];
};
int main()
{
ifstream file(&quot;filename here&quot;);
vector<xxx> vx;
xxx c;
while(file)
{
file>>x.x[1];
file>>x.x[2];
file>>x.x[3];
file>>x.x[4];
vx.push_back(c);
}
return 0;
} Ion Filipski
1c.bmp


filipski@excite.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top