Hi, everyone at the MSDN Forums.
My issue is as I said in the title: Whenever I try to use std::format in my code when using the /std:c++20 compiler switch, it gives me a compiler error saying that std::format requires /std:c++latest with Concepts support. I read on the Microsoft site that support for std::format under /std:c++20 is already complete in version 16.11. Mine is 16.11.5. So why do I have this error?
Here's one piece of code I tried:
// Osman Zakir
// 10 / 25 / 2021
// Beginning C++20: From Novice to Professional
// Chapter 2 Exercises 4 and 5
// Exercise 4 Specs:
/**
* your body mass index (BMI) is your weight, w, in kilograms divided by the square
* of your height, h, in meters ( w/(h*h) ). Write a program to calculate the BMI from a weight
* entered in pounds and a height entered in feet and inches. A kilogram is 2.2 pounds, and a foot
* is 0.3048 meters.
*/
// Exercise 5 Specs:
/**
* Knowing your BMI with a precision higher than one decimal digit after the
* decimal point is, well, pointless. Adjust the program of exercise 2-4 accordingly.
*/
import <iostream>;
import <format>;
import <cmath>;
int main()
{
std::cout << "Enter weight in pounds and height in feet and inches: ";
double w{};
double h{};
std::cin >> w >> h;
std::cin.ignore(32767, '\n');
constexpr double lbs_to_kg{ 2.2046 };
constexpr double ft_to_meters{ 0.3048 };
const double w_kg{ w / lbs_to_kg };
const double h_meters{ h * ft_to_meters };
const double bmi{ w_kg / std::pow(h_meters, 2) };
std::cout << std::format("Your BMI is {:.1f}kg/m2\n", bmi);
}
Compiler Command Line:
/JMC /permissive- /MP /ifcOutput "Debug\" /GS /analyze- /W3 /Zc:wchar_t /ZI /Gm- /Od /sdl /Fd"Debug\vc142.pdb" /Zc:inline /fp:precise /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /errorReport:prompt /WX- /Zc:forScope /RTC1 /Gd /Oy- /MDd /std:c++latest /FC /Fa"Debug\" /EHsc /nologo /Fo"Debug\" /Fp"Debug\chapter2ex4.pch" /diagnostics:column
Any help is appreciated. Thanks.