Visual studio / c++17 question?

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
What version of Visual Studio do you use?

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.
Hello DonnaPin,

My experience with 2017 and 2019 is that the minimum standard is C++14 for both.

The option to use C++17 is available for both, but has to be set for each solution/project. I have yet to find a way to make the change permanent.

I tend to use the 2019 version for C programs and anytime I need the 2017 standards.

A bit inconvenient, but maybe that is Microsoft's way to get you to pay for the program.

Anytime I have used the '17 standards I have not noticed any problems.

Andy
The option to use C++17 is available for both, but has to be set for each solution/project. I have yet to find a way to make the change permanent.

http://www.cplusplus.com/forum/lounge/271176/#msg1169093

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.

I also default set "Disable Language Extensions" so I get "pure" C++.
https://www.learncpp.com/cpp-tutorial/configuring-your-compiler-compiler-extensions/

If'n I create a Windows GUI app project/solution compilation will error out, so enabling language extensions is now a toggle instead of the default.
@ Furry Guy,

Thank you. Looks like I was making changes in the wrong place.

I will look into your links in more depth.

Andy
Thank you all for the answers, very helpful.

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 (auto const& 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.
@DonnaPin,
I am sorry.
You are right, I just forgot that insert returns a pair.
Topic archived. No new replies allowed.