
- The C Standard Library
- The C Standard Library
- The C++ Standard Library
- C++ Library - Home
- C++ Library - <fstream>
- C++ Library - <iomanip>
- C++ Library - <ios>
- C++ Library - <iosfwd>
- C++ Library - <iostream>
- C++ Library - <istream>
- C++ Library - <ostream>
- C++ Library - <sstream>
- C++ Library - <streambuf>
- C++ Library - <atomic>
- C++ Library - <complex>
- C++ Library - <exception>
- C++ Library - <functional>
- C++ Library - <limits>
- C++ Library - <locale>
- C++ Library - <memory>
- C++ Library - <new>
- C++ Library - <numeric>
- C++ Library - <regex>
- C++ Library - <stdexcept>
- C++ Library - <string>
- C++ Library - <thread>
- C++ Library - <tuple>
- C++ Library - <typeinfo>
- C++ Library - <utility>
- C++ Library - <valarray>
- The C++ STL Library
- C++ Library - <array>
- C++ Library - <bitset>
- C++ Library - <deque>
- C++ Library - <forward_list>
- C++ Library - <list>
- C++ Library - <map>
- C++ Library - <queue>
- C++ Library - <set>
- C++ Library - <stack>
- C++ Library - <unordered_map>
- C++ Library - <unordered_set>
- C++ Library - <vector>
- C++ Library - <algorithm>
- C++ Library - <iterator>
- C++ Programming Resources
- C++ Programming Tutorial
- C++ Useful Resources
- C++ Discussion
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C++ IOS Library - good
Description
It is used to check whether state of stream is good.
Declaration
Following is the declaration for ios::good() function.
bool good() const;
Parameters
none
Return Value
True if none of the stream's state flags are set.
False if any of the stream's state flags are set (badbit, eofbit or failbit).
Exceptions
Strong guarantee − if an exception is thrown, there are no changes in the stream.
Data Races
Accesses the stream object.
Concurrent access to the same stream object may cause data races.
Example
In below example explains about ios::good().
#include <iostream> #include <sstream> void print_state (const std::ios& stream) { std::cout << " good()=" << stream.good(); std::cout << " eof()=" << stream.eof(); std::cout << " fail()=" << stream.fail(); std::cout << " bad()=" << stream.bad(); } int main () { std::stringstream stream; stream.clear (stream.goodbit); std::cout << "goodbit:"; print_state(stream); std::cout << '\n'; stream.clear (stream.eofbit); std::cout << " eofbit:"; print_state(stream); std::cout << '\n'; stream.clear (stream.failbit); std::cout << "failbit:"; print_state(stream); std::cout << '\n'; stream.clear (stream.badbit); std::cout << " badbit:"; print_state(stream); std::cout << '\n'; return 0; }
Let us compile and run the above program, this will produce the following result −
goodbit: good()=1 eof()=0 fail()=0 bad()=0 eofbit: good()=0 eof()=1 fail()=0 bad()=0 failbit: good()=0 eof()=0 fail()=1 bad()=0 badbit: good()=0 eof()=0 fail()=1 bad()=1
ios.htm
Advertisements