小编Ale*_*ell的帖子

std :: setprecision没有显示尾随小数

我试图将double和整数打印为double.为此,我编写了以下程序:

int main()
{
    string object="1";
    std::stringstream objectString;
    objectString << std::setprecision(8) << atof(object.c_str());                
    cout<<"ObjectString="<<objectString.str()<< " "<<std::setprecision(10) <<  double(atof(object.c_str())) <<"\n";
}
Run Code Online (Sandbox Code Playgroud)

我期望输出为:

ObjectString=1.0  1.0
Run Code Online (Sandbox Code Playgroud)

但是,我得到的输出为:

ObjectString=1  1
Run Code Online (Sandbox Code Playgroud)

有人可以建议我哪里出错了吗?

c++ c++11

1
推荐指数
1
解决办法
226
查看次数

从c ++中的函数返回时的分段错误

我使用stringstream来解析字符串,但是它在退出函数时意外地给出了分段错误.

bool check_if_condition(int a)
{
    string polygonString1="19.922379 51.666267 19.922381 51.665595 19.921547 51.665705 19.921218 51.665753 19.920787 51.665815 19.919753 51.665960 19.919952 51.666897 19.920395 51.666826 19.920532 51.667150 19.920830 51.667748 19.920989 51.667905 19.921690 51.667906 19.922141 51.662866 19.922855 51.668696 19.922664 51.668237 19.922610 51.668025 19.922464 51.667451 19.922355 51.666732 19.922379 51.666267";

    double buf1; // Have a buffer string
    stringstream ssPolygonString1(polygonString1); // Insert the string into a stream

    double polygon1[2]; // Create vector to hold our words
    int iterPoly1=0;
    while (ssPolygonString1 >> buf1)
    {
        polygon1[iterPoly1]=(buf1);       
        cout<<"buf1="<<buf1<<"\n";
        iterPoly1++;
    } …
Run Code Online (Sandbox Code Playgroud)

c++ string stringstream c++11

-2
推荐指数
1
解决办法
299
查看次数

标签 统计

c++ ×2

c++11 ×2

string ×1

stringstream ×1