Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
getline在固定数组上循环的正确方法是什么?如果在读取字符块中找不到分隔符,则以下循环将停止。
getline
char data[4]; while (cin.getline(data, 4, '.')) { ... }
将导致循环失败的示例数据:
asdasdasdasd.asdasdasd
getline“在固定阵列上循环的正确方法是什么?”
char
可能的解决方案:
std::string token; while (std::getline(std::cin, token, '.')) { if (token.empty()) { // TODO continue; // ? } if (token.size() == 4) { // TODO } else { // TODO } }