文件IO - c++文本文件borland

file io - c++ textfile borland

本文关键字:文件 borland 文本 IO c++      更新时间:2023-10-16

我问在文本文件中的第k行中查找的函数和在c++中按行或按字符读取文本文件的函数!知道我在和borland合作。

fpeek是一个开源应用程序。检查来源,看看它是如何完成的。

我快速看了一下,我相信你最终会得到这样的东西(我还没有测试过这段代码):

std::ifstream file(filename);
std::string line;
int pos = 1; 
while (std::getline(file, line))
{   
    // Find if current line should be displayed
    if (15 == pos) // looking for the 15th line in the file
    {   
        std::cout << pos << ": " << line << std::endl;
    }   
    pos++;
}