The problem is that i dont know how to do because 'getline' won't work i think.
the file looks like this:
*******************
Inventory of MyInventory
*******************
Some info
More info
-------------------
000 Toys 6.25
a short description
126/44 Cards 2.25
some text
*******************
Inventory of MyInventory2
*******************
Some info
More info
-------------------
000 Toys 6.25
a short description
126/44 Cards 2.25
some text
So what I need to know:
- the name of the Inventory (MyInventory, MyInventory2...)
- the numbers in each row (000,126/44...)
- the name what it is (Toys,Cards...)
- the price (6.25,2.25...)
- and the description(problem here is, that there are not the same amount of words for each description)
I tried it with 'getline' but this is not working because the lines are so different each time.
Also I tried to use regular expressions but this is ways over my current skill level :S
You sure you tried getline?
I think you may have tried it, but may have tried using it incorrectly.
Let's say your file is called "herp.txt" and it's in the same directory as your .exe for your program
#include <fstream>
#include <string>
#include <iostream>
usingnamespace std;
int main()
{
ifstream MyFile;
MyFile.open("herp.txt");
if (MyFile.is_open())
{
cout << "File successfully opened. Reading and displaying output from the file." << endl;
while (!MyFile.eof())
{
string LineFromFile;
getline(MyFile,LineFromFile);
cout << LineFromFile << endl;
}
cout << "We have reached the end of the file. All of its contents have been displayed." << endl;
} else
{
cout << "Error! Could not find file" << endl;
}
system("pause");
return 0;
}
I forget to mention, that I need to put
- the name of the Inventory (MyInventory, MyInventory2...)
- the numbers in each row (000,126/44...)
- the name what it is (Toys,Cards...)
- the price (6.25,2.25...)
- and the description(problem here is, that there are not the same amount of words for each description)
in a variable for a later use.
So when I read the file I want to store the name of the inventory, the numbers and all that stuff in variables.