C++求助!!!任意输入浮点型数据,倒的输出。。

来源:百度知道 编辑:UC知道 时间:2024/06/07 15:09:50
不能当做字符型来做。
栈也不行。。
谢谢了。。。

//确实会丢失.
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main(int argc, char* argv[])
{
vector<double> vd;
ostream_iterator<double,char> outIt(cout," ");

cout<<"Input 10 number: \b";
double tmp;
int i = 10;
while (cin>>tmp)
{
vd.push_back(tmp);
--i;
if (i == 0)
break;
}
reverse(vd.begin(),vd.end());
cout<<"倒序为:"<<endl<<'\t';
copy(vd.begin(),vd.end(),outIt);
cout<<endl;

system("pause");
return 0;
}

不用字符型来做恐怕浮点的精度会损失。。。

用rand函数可以随机产生数字