hi everyone i need some help using a .txt file and allocate the values from the text to a structure :
\\content of the file :
" FluidMechanics Frank_White 1991
the_alchemist Paulo_Coelho 1988"
\\my structure :
typedef struct
{
char tittle[30];
char author[30];
int editionYear[10];
}book;
plzzz help ...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
struct book
{
std::string title;
std::string author;
std::vector<int> editionYear;
};
std::vector<book> books;
std::ifstream fin("input.txt");
while (! fin.eof() )
{
std::string line;
std::getline(fin, line);
std::stringstream iss(line);
book temp;
iss >> temp.title >> temp.author;
while (! iss.eof() )
{
int year;
iss >> year;
temp.editionYear.push_back(year);
}
books.push_back(temp);
}
|
It looks like you're in C, but I only know C++ , sorry.
Last edited on
thanx for your help, i'll try it .