Hi guys
I've just started playing with reading files and am unsure how to read in files that have the foloowing format:
<string> <string> <int>
<string> <string> <int>
....
A white space seperates each entry in the file.
Heres my code to date:
Code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main(int argc, char* argv[])
{
string str1, str2, input, temp;
int int1;
ifstream file ("test.txt");
if (file.fail()){
cout << "error on opening file";
}
if (file.is_open()){
while (!file.eof())
{
file >> input;
//how to get individual parts???
// str1 = 1st string
// str2 = 2nd string
// int1 = int
cout << "str1: " << str1
<< ", str2: " << str2
<< ", int1: " << int1 << endl;
}
}
file.close();
cin.ignore();
cin.ignore();
return 0;
}
Any ideas what I need to do?
BTW - Is the approach I've gone through so far the best??
Thanks in advance