std::stringstream is ( "a12.34e" );
double d;
char c;
is >> c >> d;
// d = 0
如何让它读取std::fixed
而不是std::scientific
(12.34e + 001)?
答案 0 :(得分:0)
在数字后删除e得到12.34作为输出。
正如您问题的第一条评论所示,以下内容也适用:
#include <cstdio>
int main() {
double d;
char c;
sscanf("a12.34e", "%c%lf", &c, &d);
printf("%c %lf\n", c, d);
return 0;
}
输出:12.340000
答案 1 :(得分:-3)
std::stringstream is ( "a12.34e" );
double d;
char c;
is >> c >>std::fixed >> d;