防止小数点前的零显示在C++; C++中,我使用以下语句显示输出: // example float x = 0.66004; cout.setf(ios::fixed); cout.setf(ios::showpoint); cout.precision(2); cout << x;

防止小数点前的零显示在C++; C++中,我使用以下语句显示输出: // example float x = 0.66004; cout.setf(ios::fixed); cout.setf(ios::showpoint); cout.precision(2); cout << x;,c++,output,setf,C++,Output,Setf,如何防止显示小数点前的零?我想: .66 std::string Foo=std::to_string(0.553); std::size\u t it=Foo.find(“.”); if(it!=std::string::npos) { std::cout一个可能的解决方案是将x转换为字符串(选项),并将小数点前的所有内容都切掉。谢谢!我没有想过使用字符串。我想可能会有某种setf修饰符用于此。 .66 std::string Foo = std::to_string(0.553); st

如何防止显示小数点前的零?我想:

.66
std::string Foo=std::to_string(0.553);
std::size\u t it=Foo.find(“.”);
if(it!=std::string::npos)
{

std::cout一个可能的解决方案是将
x
转换为字符串(选项),并将小数点前的所有内容都切掉。

谢谢!我没有想过使用字符串。我想可能会有某种setf修饰符用于此。
.66
std::string Foo = std::to_string(0.553);
std::size_t it = Foo.find(".");

if (it != std::string::npos)
{
    std::cout<<Foo.erase(0, it);
}