EOF in Visual C++?

I'm using Microsoft Visual C++ 2010 Express, and I was told that to send an EOF (end-of-file) signal to the console I should do: ENTER + Ctrl-Z + ENTER.

1
2
3
4
5
6
cout << "Enter all your homework grades, "
	        "followed by end-of-file: ";

    // the number and sum of grades read so far
    int count = 0;
    double sum = 0;


I press Ctrl-Z, it prints "^Z" on the screen. Next, I press ENTER and the program terminates.
Is this because the program asks for numbers (int, double) and I'm entering a string?
How do I send the EOF signal?

All help appreciated.
Bump :(

Somebody using Microsoft Visual C++ 2010 Express familiar with sending end-of-file signal?
ENTER + Ctrl-Z + ENTER does not work.
Nor ENTER + ENTER + ENTER etc. + Ctrl-Z + ENTER

Thanks in advance! :)
I finally found out that ENTER + Ctrl-Z + ENTER actually works :p

The problem was that the program terminated prematurely. I was using cin.get(); , so when I tried
system("pause"); the program ran fine.

The program:
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
#include <iomanip>
#include <ios>
#include <iostream>
#include <string>

using std::cin;                  using std::setprecision;
using std::cout;                 using std::string;
using std::endl;                 using std::streamsize;

int main()
{
    // ask for and read the student's name
    cout << "Please enter your first name: ";
    string name;
    cin >> name;
    cout << "Hello, " << name << "!" << endl;

    // ask for and read the midterm and final grades
    cout << "Please enter your midterm and final exam grades: ";
    double midterm, final;
    cin >> midterm >> final;

    // ask for the homework grades
    cout << "Enter all your homework grades, "
	        "followed by end-of-file: ";

    // the number and sum of grades read so far
    int count = 0;
    double sum = 0;

    // a variable into which to read
    double x;

    // invariant:
    // we have read count grades so far, and
    // sum is the sum of the first count grades
    while (cin >> x) {
        ++count;
        sum += x;
    }

    // write the result
    streamsize prec = cout.precision();
    cout << "Your final grade is " << setprecision(3)
         << 0.2 * midterm + 0.4 * final + 0.4 * sum / count
         << setprecision(prec) << endl;

system("pause");
    return 0;
}


How can I replace system("pause");, and why won't cin.get(); work?
It's not a Visual Studio thing, it's Microsoft's shell, cmd.exe, thing.

It's been inherited from DOS which uses an older version of the same shell. Also F6 sends EOF and EOF is ASCII 26, which is why Ctrl-z works.
Topic archived. No new replies allowed.