Question

std::defaultfloat doesn't seem to be defined in GCC, despite being in the standard (I think it's §27.5.6.4). I've isolated it to this simple program:

// test.cpp
#include <iostream>                                                             

int main()                                                                      
{                                                                               
    std::cout << std::defaultfloat << 1.3;                                      
    return 0;                                                                   
}

This compiles in VC++11. I tried compiling this with g++ 4.7.2 and g++ 4.9.0 using both of these commands:

g++ test.cpp g++ test.cpp -std=c++11

I also tried an online compile on GCC 4.8.1 here, always with the same result:

user@office-debian:~/Documents/test$ g++ test.cpp -std=c++11
test.cpp: In function ‘int main()’:
test.cpp:5:15: error: ‘defaultfloat’ is not a member of ‘std’
  std::cout << std::defaultfloat << 1.3;

Why am I getting this error?

Was it helpful?

Solution

GCC libstdc++ just doesn't support these C++11 manipulators in any of the versions you've compiled against. A patch was submitted exactly one month ago

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top