Hi, I dont have a problem, but I am self learning so I dont really have anywhere else to ask these question, so hoping someone could help me out.
I am learning sets, and wanting to use structured binding with them, but read that it was new with c++17, and when I tried to use it in visual studio I was getting errors. Long story short I had to find and change the settings in my visual studio. My question is, why is c++17 not the default settings on visual studio if its the newest (although I think there might be a 20 but not sure). In my settings it was just set to default, what is default? Can there be problems with me changing to c++17? Does it not change to 17 or even 14, incase it messes up old code? Thanks for any help
I am learning sets, and wanting to use structured binding with them
Maybe you confuse sth. structured bindings makes no sense with std::set.
A common use for structured bindings would be std::tuple or std::pair or std::map
My question is, why is c++17 not the default settings on visual studio
I guess only Microsoft knows.
In VS 2017 or VS 2019 you can safely set it to C++17. I never had problems with it.
The same procedure for adding a library file dependency can be used to set a number of defaults in VS 2017 or 2019. I've set C++17 as the default so every new project/solution uses it as the default.
When VS 2019 has actual C++20 support instead of C++2a (latest) I'll modify the defaults again.
The option to use C++17 is available for both, but has to be set for each solution/project
I was wondering about this when I was trying to set it, as I was sure I had changed vs to c++17 a few months ago and I couldnt figure out why it wasnt working now for this project, but I guess this now answers my question, I need to do it for each solution.
What version of Visual Studio do you use?
I am using 2019
Maybe you confuse sth. structured bindings makes no sense with std::set.
A common use for structured bindings would be std::tuple or std::pair or std::map
I am using the structured bindings with a set to check on an insert operation. I found this in a tutorial, so not sure if it should be used this way, just following along with the tutorials.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
std::set<int> nums{ 1,2,3,4,5 };
for (autoconst& n : nums)
{
std::cout << n << ' ';
}
std::cout << "\n";
auto [it, inserted] = nums.insert(4);
if (inserted == true)
{
std::cout << "New number added\n";
}
else
{
std::cout << "Number already exists\n";
}
I was wondering about this when I was trying to set it, as I was sure I had changed vs to c++17 a few months ago and I couldnt figure out why it wasnt working now for this project, but I guess this now answers my question, I need to do it for each solution.
You CAN change it globally so it becomes the new default, it just requires a bit of work. See my previous post for links how to make the changes.
It really isn't as difficult as it seems to be, the changes can be done in just a couple of minutes.