Starts, works fine, then quits.

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
#include<iostream>
using namespace std;

namespace alpha
{
 long int vari;
}
namespace beta
{
 long int vari;          
}
int main ()
{
 long int dos;
 cout << "Enter a number: ";
 cin >> alpha::vari; 
 cout << "Enter another number: ";
 cin >> beta::vari;
 dos = alpha::vari * beta::vari;
 cout << alpha::vari << " times " << beta::vari << " is " << dos << ".\n";
 cout << "Press RETURN/ENTER to continue...\n"; 
 cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n' ); 
 
 return 0;
}

This program was just a namespace test, but it quits at line 19, where it is supposed to continue. Any ideas?
Three things:

1) It works fine for me. (I cannot replicate your error.)

2) You forgot to #include <limits>

3) You need to replicate line 22 before line 21 also.

Hope this helps.
Well, did three, and it worked. <limits> wasn't needed.
If you use numeric_limits, you need <limits>, whether your compiler complains or not.

Glad to have helped.
Duoas ..
it works without including <limits>..!!
I'm using DevC++
So?

It doesn't work with VC++ or C++Builder. Just because your compiler lets you get away with something doesn't mean you should do it.

I primarily use the GCC myself, and I've been bit by this very issue.

If you use numeric_limits, you need <limits>, whether your compiler complains or not.
Topic archived. No new replies allowed.