#include
#include
#include
using namespace std;
int main()
{
int num=10;
string str,longstr="";
stringstream ss;
int *list=new int[num];
std::cout<<"Hello world!"<<std::endl;
srand((unsigned int)time(0));
for(int i=0;i<num;i++){
list[i]=rand();
ss<<list[i];
str=ss.str();
longstr=longstr+str+'\n';
}
std::cout<<longstr;
return 0;
}
輸出是:
Hello world!
11391
1139120221
11391202218590
1139120221859029226
11391202218590292261048
1139120221859029226104827899
11391202218590292261048278996273
1139120221859029226104827899627323760
11391202218590292261048278996273237603823
1139120221859029226104827899627323760382316476
請按任意鍵繼續. . .
我希望的輸出是:
11391
20221
8590
29226
longstr=longstr+str+'\n';
上面這句改為longstr = str+'\n';試試