Let's say you have the following simple main.cpp file:
#include <cstdlib> #include <iostream> #include <fstream> using namespace std; int main() { const string FILENAME = "foo.txt"; ifstream somefile(FILENAME); populations.close(); return 0; }
This compiles using Visual Studio C ++ 2010.
However, on a Linux-based system, if I execute make main
and compile, we get the expected error, since we did not call c_str()
in a string constant, for example:
ifstream somefile(FILENAME.c_str());
As is well known and described in this SO stream .
How can I make VS behave like gcc / g ++ and raise a compilation error for the code above? Or, how can I get gcc / g ++ to behave like VS and compile above without errors? (Is it just a matter of updating my gnu compiler?)
(I donβt think that disabling compiler extensions is a solution, as I did, and it still compiles without errors.)
source share