12345678910111213141516
#include <iostream> #include <sstream> #include <string> int main(){ std::stringstream stream; // stream << "(thousands of numbers)"; unsigned long long temp = 0; short int smallInt = 0; std::string tempString; stream.seekg(40); smallInt.get(temp, 10); std::cout << "temp = " << temp << std::endl; std::cout << std::endl; }
12
short int smallInt = 0; smallInt.get(temp, 10);
If the file is in text format
stream << "43364936946349";
In binary format you can read 10 numbers as a block.
1234567891011121314151617
#include <iostream> #include <string> #include <sstream> #include <iomanip> int main() { std::istringstream stm( "01234567892535365789007676352418791476830807574352224586869912345" ) ; // read 10 characters (digits) at a time std::string s10 ; while( stm >> std::setw(10) >> s10 ) { const long long int_val = std::stoll(s10) ; // may throw if the string is not well-formed std::cout << "string: " << std::quoted(s10) << " integer value: " << int_val << '\n' ; } }
12345678910111213141516171819202122232425262728293031
# include <iostream> # include <string> # include <sstream> # include <iomanip> # include <iterator> # include <vector> int main() { std::istringstream stm( "01234567892535365789007676352418791476830807574352224586869912345" ) ; std::istreambuf_iterator<char> eos; std::istreambuf_iterator<char> iit(stm); std::vector<std::string> numbersTenDigits{}; std::string stringOfTen; while (iit != eos) { for (size_t i = 0; i <= 9; ++i) { stringOfTen += *iit++; if(i == 9) { numbersTenDigits.push_back(std::move(stringOfTen)); stringOfTen.clear(); } } } if(stringOfTen.size())numbersTenDigits.push_back(std::move(stringOfTen)); for (const auto& elem : numbersTenDigits)std::cout << elem << "\n"; }
#include <iostream> #include <string> #include <sstream> #include <vector> int main() { std::istringstream stm( "253536578987907676352411476808075743522245868699961234" ) ; std::vector<std::string> vec ; char arr[10] ; std::streamsize n ; while( ( n = stm.rdbuf()->sgetn( arr, sizeof(arr) ) ) > 0 ) vec.emplace_back( arr, arr+n ) ; for( const std::string& str : vec ) std::cout << str << '\n' ; }