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 << ":";