Posts

Showing posts with the label visual-studio

Why is the Visual Studio Community 2017 C++ standard C++98?

Yesterday I upgraded to the latest VS Community 2017 (the previous one was installed last year) and wanted to check the C++ standard. So I run the following code that checks it, and as it turns out, I have C++98: #include<iostream> using namespace std; int main() { cout << __cplusplus << endl; system("pause"); } Which outputs 199711 Why don't I have the latest C++ standard? The value of __cplusplus is temporarily intentionally non-conformant by default for current versions of Visual Studio in order to avoid breaking existing code. It does not mean your compiler does not support any C++11 (or newer) features. Quoting from MSVC now correctly reports __cplusplus: /Zc:__cplusplus You need to compile with the /Zc:__cplusplus switch to see the updated value of the __cplusplus macro. We tried updating the macro by default and discovered that a lot of code doesn’t compile correctly when we change the value of __cplusplus. We’ll continue to r...

Why can std:set (with a single colon) compile?

I accidentally wrote std::set<string> keys; as: std:set<string> keys; but weirdly enough, Visual Studio 2013 still compiles. Why does this happen? Actually keys is not only defined, but later used as a set of strings, such as if(keys.find(keystr)==keys.end()){ keys.insert(keystr); toret.push_back(tempv); } At block scope, an identifier followed by a single colon introduces a label. Thus, your statement is equivalent to: set<string> keys; except that it bears the label std and can be jumped to by the statement goto std;. For some reason, the name set is known to the compiler---perhaps you did using namespace std;, or using std::set;, or something like that, or perhaps you defined your own set type somewhere. In the second case, std is a label. It is the same as spelling default incorrectly in a case statement.