The C++ std::ios::skipws() function is a manipulator used with the input streams. When it is invoked on the input stream, it makes the stream to skip any whitespace characters (spaces, tabs, newlines) before extracting the actual input. This ensures that whitespace does not interfere with reading data from the stream.
SyntaxFollowing is the syntax for std::ios::skipws() function.
ios_base& skipws (ios_base& str);Parameters
This function returns the Argument str.
ExceptionsIf an exception is thrown, str is in a valid state.
Data racesIt modifies str. Concurrent access to the same stream object may cause data races.
ExampleIn the following example, we are going to consider the basic usage of the skipws() function.
#include <iostream> #include <sstream> int main() { std::istringstream x(" 1 12"); int a, b; x >> std::skipws >> a >> b; std::cout << "a: " << a << ", b: " << b << std::endl; return 0; }Output
Output of the above code is as follows −
a: 1, b: 12Example
Consider the following example, where we are going to disable the skipws() function.
#include <iostream> #include <sstream> int main() { std::istringstream a(" 1 22"); int x, y; a >> std::noskipws >> x >> y; std::cout << "x : " << x << ", y : " << y << std::endl; return 0; }Output
Following is the output of the above code −
x : 0, y : 32761
ios.htm
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4