#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