这可能是因为文件的编码方式与程序的默认编码方式不同导致的。可以尝试修改程序的编码方式或将文件的编码方式转换为与程序相同的编码方式。另外,也可以尝试使用文件流的 getline 函数逐行读取文件并输出。例如:

void print_announcement() { std::string fileName = "D:\announcement.txt"; std::ifstream file(fileName);

if (file.is_open())
{
    std::string line;
    while (std::getline(file, line))
    {
        std::cout << line << std::endl;
    }
    file.close();
}
else
{
    std::cout << "Unable to open file" << std::endl;
}

}

void print_announcement stdstring fileName; fileName = Dannouncementtxt; stdifstream filefileName; if fileis_open char c; while filegetc

原文地址: https://www.cveoy.top/t/topic/g2Qg 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录