By Trí Lê


2020-03-26 03:10:26 8 Comments

I have a file.txt like this

2
1
iPhone XS Max
40000000
2
Samsung Galaxy Note 10 Plus
2
25000000

Number 2 (which is n) in the first line illustrate the quantity of items listed which is iPhone and Samsung. Except the names of two phones which is char, the others are int.

void readFraction(ifstream  &filein, Fraction& f)
{
filein >> f.id;
filein.getline(f.name,100);
filein >> f.stock;
filein >> f.price;
}

void readFractionArray(ifstream& filein, Fraction fr[], int n)
{
    for (int i = 0; i < n; i++)
    {
        readFraction(filein, fr[i]);
    }
}
void loadFraction(Fraction f)
{
    cout << f.id << "\n" << f.name << "\n" << f.stock << "\n" << f.price;
}
void loadFractionArray(Fraction fr[], int n)
{
    for (int i = 0; i < n; i++)
    {
        cout << endl;
        loadFraction(fr[i]);
    }
}

Here is my code to read and load file.txt but it seems not working. So what is my mistake here ?

Here is the result image

0 comments

Related Questions

Sponsored Content

8 Answered Questions

[SOLVED] Read file line by line using ifstream in C++

28 Answered Questions

[SOLVED] How to read a file line-by-line into a list?

27 Answered Questions

[SOLVED] Easiest way to convert int to string in C++

12 Answered Questions

[SOLVED] Convert char to int in C and C++

  • 2011-02-17 13:57:37
  • mainajaved
  • 1659172 View
  • 377 Score
  • 12 Answer
  • Tags:   c++ c gcc

26 Answered Questions

[SOLVED] How can I get the list of files in a directory using C or C++?

  • 2009-03-04 19:35:58
  • samoz
  • 863462 View
  • 576 Score
  • 26 Answer
  • Tags:   c++ c file directory

24 Answered Questions

[SOLVED] What does the C++ standard state the size of int, long type to be?

  • 2009-02-26 07:59:23
  • Jérôme
  • 1218378 View
  • 693 Score
  • 24 Answer
  • Tags:   c++ c++-faq

10 Answered Questions

31 Answered Questions

[SOLVED] How to read all files in a folder from Java?

8 Answered Questions

[SOLVED] What does int argc, char *argv[] mean?

Sponsored Content