我需要在其中组织带有符号分析的无限循环.在使用的CI中fgets(buf, N, stdin),假设buf是buf[10].用户可以输入任意长度的字符串,我可以通过分解输入并检查长度为10的部分来分析它.如何在不使用C库的情况下在C++中实现它.如果你不明白我的意思,抱歉我的英语
在C++中,您应该std::cin从标准输入中读取.
// #include <iostream>
do
{
char buf[10]{}; // create array of 10 bytes filled with zeros.
std::cin.read(buf, 10); // read 10 bytes
// at this point you should check if std::cin.read succeeded.
// otherwise you will be reading zeros.
std::streamsize numRead = std::cin.gcount(); // obtain number of read bytes.
std::cout << numRead << " " << buf << std::endl; // some printing.
}while(std::cin);
Run Code Online (Sandbox Code Playgroud)