Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/152.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 成员函数中的setfill问题_C++ - Fatal编程技术网

C++ 成员函数中的setfill问题

C++ 成员函数中的setfill问题,c++,C++,我试图在多个文件上创建一个程序来读取时间,但在以所需格式显示时间时遇到了问题。更具体地说,setfill似乎给我带来了问题 下面是我在编译时收到的很长错误消息的开头: error: no match for ‘operator<<’ in ‘std::operator<< [with _CharT = char, _Traits = std::char_traits<char>](((std::basic_ostream<char, std::cha

我试图在多个文件上创建一个程序来读取时间,但在以所需格式显示时间时遇到了问题。更具体地说,
setfill
似乎给我带来了问题

下面是我在编译时收到的很长错误消息的开头:

error: no match for ‘operator<<’ in ‘std::operator<< [with _CharT = char, 
_Traits = std::char_traits<char>](((std::basic_ostream<char, 
std::char_traits<char> >&)(& std::cout)), std::setw(2)) << std::setfill 
[with _CharT = const char*](((const char*)"0"))’
要明确的是,我已经包括了
iomanip
setw
自己工作没有问题


谢谢。

setfill需要一个字符,它应该是
'0'
而不是
'0'

setfill需要一个
字符,而不是
字符*
,所以它应该是
'0'
你应该:

cout << setw (2) << setfill ('0') << hours << ":";
cout << setw (2) << setfill ('0') << minutes << ":";
cout << setw (2) << setfill ('0') << seconds << endl;

cout此外,如果您使用的是wstringstream,setfill需要一个wchar

比较

std::stringstream ss;
ss << std::setw(2) << std::setfill('0') << hours << ":";
std::stringstream-ss;
请注意,
“0”
是一个
常量字符*
,而不是
字符*
std::stringstream ss;
ss << std::setw(2) << std::setfill('0') << hours << ":";
std::wstringstream ss;
ss << std::setw(2) << std::setfill(L'0') << hours << ":";