Use a stringsteam:
#include <string>
#include <sstream>
int main() {
std::string s = "100 123 42";
std::istringstream is( s );
int n;
while( is >> n ) {
// do something with n
}
}
More Related Contents:
- Insertion sort stops working after million input
- Why the values {1, 1, 0, -1, -1, -1, 0, 1} and {0, 1, 1, 1, 0, -1, -1, -1} were chosen for dx[dir] and dy[dir]? [closed]
- What is the difference between public, private, and protected inheritance in C++?
- When to use volatile with multi threading?
- Accessing inactive union member and undefined behavior?
- How to add “-l” (ell) compiler flag in CMake
- AVX2 what is the most efficient way to pack left based on a mask?
- How to use Boost in Visual Studio 2010
- C++ templates that accept only certain types
- C++ Cross-Platform High-Resolution Timer
- Why is there an injected class name?
- How do I erase an element from std::vector by index?
- What is the difference between atan and atan2 in C++?
- How to enable C++11 in Qt Creator?
- Instantiate class from name?
- how to check whether two matrices are identical in OpenCV
- reading a line from ifstream into a string variable
- Are C++ Templates just Macros in disguise?
- Most efficient/elegant way to clip a number?
- How to append a char to a std::string?
- Writing robust (color and size invariant) circle detection with OpenCV (based on Hough transform or other features)
- Why doesn’t C++ support named parameters?
- Why “initializer-string for array of chars is too long” compiles fine in C & not in C++?
- Why can’t std::ostream be moved?
- Strange ambiguous call to overloaded function error
- Problems with running EXE file built with Visual Studio on another computer
- Dead code identification (C++)
- Getting the current time (in milliseconds) from the system clock in Windows?
- BOOST libraries in multithreading-aware mode
- Passing a C++ complex array to C