#include <iostream>
#include <math.h>
#include <iomanip>
#include <sstream>
#include <stdio.h>
#include <string>
#include <stdlib.h>
using namespace std;
int main()
{
ostringstream str;
double num = pow(2,1000);
int sum = 0;
str << setprecision(1000) << num;
string here = str.str();
cout << here << "\n\n";
/*for(int i = 0; i < here.length(); i++)
{
sum += atoi(&here[i]);
}*/
cout << atoi(&here[0]);
cout << atoi(&here[1]);
cout << atoi(&here[2]);
}
输出:的atoi()只给0结果
10715086071862673209484250490600018105614048117055336074437503883703510511249361
22493198378815695858127594672917553146825187145285692314043598457757469857480393
45677748242309854210746050623711418779541821530464749835819412673987675591655439
46077062914571196477686542167660429831652624386837205668069376
000
为什么全0?
我想你不想'atoi'可言,我想你想简单地减去''0 ''(即文本数字零的字符常量)。看起来好像你想要对字符串中的每个数字进行求和。如果是这种情况,你不会希望使用'atoi'。使用'sum + = here [i] - '0';'在你的循环中 – dreamlax 2013-03-03 06:15:17
思考实验:* atoi *返回类型可以表示的最大数量是多少?第二个想法:双精度浮点数可以表示多少个有效数字。 – Digikata 2013-03-03 06:15:39
在我的系统上运行的相同程序给出了3个-1而不是3个零。就像其他人指出的那样,我觉得这是因为错误。 – Tuxdude 2013-03-03 06:17:39