I'm trying to read from a textfile and then trying to place those in an object.
But I am not sure how to seperate a line into two variables (space as a delimiter).
The text file format is as follows (first 2 entries):
Text1 [txt1]
This is a description of text 1.More description of Text 1 here blah blah blah.
Text2 [txt2]
This is the description of text 2.
I would like to place them into three sperate variables, one for the name (Text1), type which are the square brackets ([txt1) and finally the description (This is a description of text 1.)
I have the following code so far which does not seperate Text1 and [txt1]:
if (myfile.is_open()) {
string buffer;
string currentText= "empty";
string currentType= "empty";
string currentDescription = "empty";
while (!myfile.eof()) {
getline(myfile, buffer); // Would like to seprate this line into two variables
currentText = buffer;
if (buffer == "") continue;
getline(myfile, buffer);
currentDescription = buffer;
if (buffer == "") continue;
TextObj newtext(currentText, iWantToEnterTypeHere, currentDescription);
this->textVector.push_back(newText);
}
myfile.close();
I hope this made sense, I would appreciate any help. Cheers