Ahm*_*med 2 c++ scanf format-specifiers
我有以下代码:
#include <cstdio>
int main()
{
float b = 323.23f;
std::scanf("%6.3f\n", &b); // <-- Warning
std::printf("%6.3f\n", b);
}
Run Code Online (Sandbox Code Playgroud)
有一个警告scanf()说:
转换说明符无效
'.'
这里有什么我想念的吗?
使用%6.3f时printf,.3指定输出的精度.
scanf不需要您指定精度,因为它将接受它在输入流中找到的任何精度.因此,您不能以格式指定.3(或.-anything-else)scanf.只是使用%6f甚至%f改为.