How to refer to iostate?

Hi, folks:
i have written a program that uses an iostream member type iostate, i worte some code like those at the beginning of source file, but it seems wrong:
1
2
#include<istream>
using istream::iostate
how can i refer to it? Thanks!
Last edited on
does anybody know that? The iostate is a Standard library member type defined in ios_base header, but i don't know how to include it in my program, i would appreciate it very much if you tell me... well , all i want is to output the size of the iostate, i wrote some thing like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include<iostream>
#include<istream>
using std::cin;
using std::cout;
using std::endl;
int main()
{
int num;
cout << "Please enter a integer: " << endl;
cin >> num;
if(cin.good() )cout << "The integer is: " << num <<endl;
else {
istream::iostate state = cin.rdstate();
cout << state << endl;
}
return 0;
}
All i want is to output the state of cin! But when i compile, the compiler tells me " istream has not been declared! iostate was not declared in this scope! " What's wrong? anyone helps! Thanks!
That's because it is such an easy fix, we were letting letting you find it for yourself.

Because as you said, it is in the std library.
Do you mean i should write " using std::iostate " at the beginning of my source file? it didn't work, i tried...
std::istream::iostate state = cin.rdstate();

or you can write this:
1
2
3
4
5
6
using std::istream;

//other code
istream::iostate state = cin.rdstate()

;
Last edited on
Thanks, guestgulkan, it works!
but there still is one problem remains:
why do i have to prefix iostate by istream:: in the expression statement when i have already used using declaration at the beginning of my source file? That is, why doesn't the following code work?
1
2
using std::istream;
iostate state = cin.rdstate();

i doubt this because after i declaredusing std::cin, i can use cin in expression statement directly! Can you tell me how i can use iostate directly? Thanks!
I'd have to check through the varios headers, but if I remember correctly - iostate is a enum defined in the ios_base class which is inherited by istream and ostream

So iostate is not directly defined in the std namespace - that is why it is:
std::istream::iostate or std::ostream::iostate or std::ios_base::iostate,

but NOT std::iostate
why do i have to prefix iostate by istream:: in the expression statement when i have already used using declaration at the beginning of my source file? That is, why doesn't the following code work?
That is because istream is a class name and not a namespace. Actually iostate is a member of ios_base, but you can access it through istream since it inherits it from ios, and which ios inherits from ios_base.
http://cplusplus.com/reference/iostream/

Can you tell me how i can use iostate directly?
You can define a new type.
1
2
3
4
using namespace std;
typedef ios_base::iostate iostate;

iostate state = cin.rdstate();
Yeah, i see ...
i still have many questions about namespace , i will work harder. Thanks , you guys!
Topic archived. No new replies allowed.