Array Issue

Hi,

[output]
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
int main(int argc, const char * argv[])
{

    // insert code here...
    const int RANGE = 12;
    string tab[RANGE];
    int i = 0;
    int j = 0;
    // Add more statements here.
    ifstream reader("records.txt");
    if (!reader)
    {
        cout << "Error opening input file" << endl;
        return -1;
    }
    while (!reader.eof())
    {
        if((i + 1) % 4 == 0)
            getline(reader, tab[i++], '\n');
        else
            getline(reader, tab[i++], 't');
    }
    reader.close();
    i = 0;
    while (i < RANGE)
    {
        cout << endl << "Record Number: " << ++j << endl;
        cout << "Forename: " << tab[i++] << endl;
        cout << "Surname: " << tab[i++] << endl;
        cout << "Department: " << tab[i++] << endl;
        cout << "Telephone " << tab[i++] << endl;
    }
    return 0;
}


However I'm not sure what tab[i++] does in both while loops.

Thanks.
closed account (Dy7SLyTq)
well it takes the line of the file and puts it in tab at space [i] and then increments it
Well that was a lot easier than expected... :P. Thanks.

cout.precision(11);
cout << "Pi: " << 3.1415926536 << endl;

This is unrelated to the main program however, I just wanted to know how C++ counts through those Pi digits and how the precision function works.
closed account (Dy7SLyTq)
if i remember correctly it will only show the first 11 of the float literal digits
Yeah that seems to clear it up.

Thanks.

I have another query, I would create a new thread but I can't at the moment:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
int main(int argc, const char * argv[])
{

    // insert code here...
    string lang = "C++";
    int num = 1000000000;   // One billion.
    // Try-catch block goes here.
    cout << "Program continues..." << endl;
    try { lang.replace(100, 1, "C");}
    catch(out_of_range &e)
    {
        cerr << "Range Exception: " << e.what() << endl;
        cerr << "Exception Type: " << typeid(e).name();
        cerr << endl << "Program terminated." << endl;
        return -1;
    }
    cin.get();
    return 0;
}


I was just wondering what is Range Exception and what is Exception Type.

Thanks.
Last edited on
Topic archived. No new replies allowed.