0

OK, so this is my code:

    cout << "What is your p value?" << endl;
    unsigned long long p;
    cin >> p;
    cin.ignore();
    cout << endl;

    cout << "What is your q value?" << endl;
    unsigned long long q;
    cin >> q;
            cin.ignore();
    cout << endl;

I put the first huge value--that is, p--in, and something gets put in to q automatically even with these cin.ignore()'s. What issues am I not seeing here? Please let me know if you need more information if it's not obvious to you.

[Adding information from a comment: the input value was 92896134244099469431, which exceeds 266.]

4

1 回答 1

2

You say you entered a "huge value". If that value exceeds the upper bound of unsigned long long, then cin >> p; will fail.

A quick experiment indicates that once that happens, cin >> q; doesn't do anything, and no value is stored in q. The value of p will probably be 18446744073709551615, or 264-1.

You need to check whether each input operation succeeded or failed, and decide how to handle any errors.

You also need to update your question to indicate exactly what input you provided to your program.

于 2013-06-12T22:56:17.927 回答