How to output without the first line.

I'd like to know how to output everything in the file except the 'Student's Shopping List line.

1
2
3
4
5
6
7
8
Student's Shopping List
apple 0.89
book 135.00
eraser 0.59
flashdrive 7.99
folder 1.29
highlighter 0.98
... 


Here's the rest of the code.

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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77

#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <cstdlib>

const float TAX_RATE = 0.09;

using namespace std;
float tax (float);

void heading(){
    cout << left << setw(15) << "Item";
    cout << right << setw(15) << "Cost";
    cout << right << setw(15) << "Tax";
    cout << right << setw(15) << "Subtotal" << endl;
    cout << left << setw(15) << "-----------";
    cout << right << setw(15) << "------";
    cout << right << setw(15) << "-----";
    cout << right << setw(15) << "--------" << endl;
    }

 float tax(float giveMeThePrice){
        return giveMeThePrice *= TAX_RATE;
 }
int main()
{

    ifstream infile;
    ofstream outfile;
    string product;
    float price1, taxed, sum;
    infile.open("Student'sShoppingList.txt");
    if (infile){
        outfile.open("GrandTotal.txt");
        heading();
        outfile << left << setw(15) << "Item";
        outfile << right << setw(15) << "Cost";
        outfile << right << setw(15) << "Tax";
        outfile << right << setw(15) << "Subtotal" << endl;
        outfile << left << setw(15) << "-----------";
        outfile << right << setw(15) << "------";
        outfile << right << setw(15) << "-----";
        outfile << right << setw(15) << "--------" << endl;
        while(infile >> product >> price1){
            cout << left << setw(15) << product;
            cout << right << setw(15) << setprecision(2) << fixed << price1;
            taxed = tax(price1);
            cout << right << setw(15) << setprecision(2) << fixed << taxed;
            cout << right << setw(15) << setprecision(2) << fixed << price1 + taxed << endl;
            sum = taxed + price1;
            outfile << left << setw(15) << product;
            outfile << right << setw(15) << setprecision(2) << fixed << price1;
            outfile << right << setw(15) << setprecision(2) << fixed << taxed;
            outfile << right << setw(15) << setprecision(2) << fixed << price1 + taxed << endl;
        }
        cout << "..." << endl;
        cout << right << setw(60) << "--------" << endl;
        cout << right << setw(56) << "Total: " << sum << endl;
        cout << "Total Written to GrandTotal.txt." << endl;
        outfile << "..." << endl;
        outfile << right << setw(60) << "--------" << endl;
        outfile << right << setw(56) << "Total: " << sum << endl;
        outfile << "Total Written to GrandTotal.txt." << endl;
        infile.close();
        outfile.close();
    }
    else{
        cout << "Error opening file." << endl;
    }


    return 0;
}

You could use getline() to read and throw away a line as here:

http://www.cplusplus.com/forum/beginner/222353/

or use infile.ignore(200, '\n') which ignores up to 200 characters or until a newline is found - whichever comes first.

(the more generalised form is like this:
 
infile.ignore( std::numeric_limits<std::streamsize>::max(), '\n' );

and requires #include <limits> to ignore lines of unlimited length).

Topic archived. No new replies allowed.