书上看到这个示例:
#include <iostream> #include <string> using namespace std; int main() { string buf; while (cin >> buf && !buf.empty()) cout << 1; }
我想问!buf.empty()有必要吗?,据我的理解,cin>>buf不接受空白字符,那就肯定不是空字符串了,所以while(cin>>buf)就行了.
!buf.empty()
cin>>buf
while(cin>>buf)
走同样的路,发现不同的人生
][1]
In fact, there is no need to add spaces. By default, spaces and line breaks are not accepted
][1]
In fact, there is no need to add spaces. By default, spaces and line breaks are not accepted