c++读取文件

Posted Ren.Yu

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c++读取文件相关的知识,希望对你有一定的参考价值。

 1 #include <iostream>
 2 #include <string>
 3 #include <fstream>
 4 
 5 int main() {
 6     std::ifstream in_file("test.txt");
 7     std::string line;
 8     while ( getline(in_file, line) ) {
 9         std::cout << line;
10     }
11 }

不需要检查test.txt是否存在

以上是关于c++读取文件的主要内容,如果未能解决你的问题,请参考以下文章