Hi,
I am trying to read two strings per line and store them in strings so i can use them in my program.for example if this is my input file:
cat:yellow
dog:blue
chicken:red
i wan to store cat as animal1 string dog as animal2 string and yellow as colour1 string and so on.not sure how to do this.What i got so far is reading line by line which is not what i want.
#include <fstream>
#include <string>
using namespace std;
int main () {
string line;
//the variable of type ifstream:
ifstream myfile ("example.txt");
//check to see if the file is opened:
if (myfile.is_open())
{
//while there are still lines in the
//file, keep reading:
while (! myfile.eof() )
{
//place the line from myfile into the
//line variable:
getline (myfile,line);
//display the line we gathered:
cout << line << endl;
}
//close the stream:
myfile.close();
}
else cout << "Unable to open file";
return 0;
}
would be great if someone help me with this,thank