Portál AbcLinuxu, 6. listopadu 2025 14:49
#include <sstream>
#include <iostream>
int main(int argc,char *argv[])
{
std::istringstream strm("foo");
int n = -1;
strm >> n;
std::cout << "n is " << n <<std::endl;
return 0;
}
Vypíše
n is 0
Je to bug v stdc++?
strm.fail()
c++ (GCC) 3.4.4 (cygming special, gdc 0.12, using dmd 0.125)také -1
#include <sstream>
#include <iostream>
int main(int argc,char *argv[])
{
std::istringstream strm("foo");
int n = -1;
strm >> n;
if (!strm.fail()) {
std::cout << "n is " << n <<std::endl;
}
else {
std::cout << "n does not represent a number." <<std::endl;
}
return 0;
}
Tiskni
Sdílej:
ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.