S
sergey.lukoshkin
Hello everyone!
My task is in converting numbers from string to int variables. I used
istringstream to perform it.
So I wrote simple test function. But it doesn't work as I expected
because val is not being changed while the program is running. Could
you please tell me why ??
#include <iostream>
#include <sstream>
#include <iomanip>
#include <stdint.h>
int main()
{
static std::string str;
static std::istringstream istr;
static unsigned val;
while( true )
{
std::cout << "Enter num: " << std::endl;
std::cin >> str;
istr.str(str);
istr >> val;
std::cout << "Number: " << val << std::endl;
}
return 0;
}
My task is in converting numbers from string to int variables. I used
istringstream to perform it.
So I wrote simple test function. But it doesn't work as I expected
because val is not being changed while the program is running. Could
you please tell me why ??
#include <iostream>
#include <sstream>
#include <iomanip>
#include <stdint.h>
int main()
{
static std::string str;
static std::istringstream istr;
static unsigned val;
while( true )
{
std::cout << "Enter num: " << std::endl;
std::cin >> str;
istr.str(str);
istr >> val;
std::cout << "Number: " << val << std::endl;
}
return 0;
}