C++按行读取txt 字符串

#include <fstream>  
#include <string>  
#include <iostream>  
using namespace std;  
  
int main()  
{  
    ifstream in("1.txt");  
    string filename;  
    string line;  
  
    if(in) // 有该文件  
    {  
        while (getline (in, line)) // line中不包括每行的换行符  
        {   
            cout << line << endl;  
        }  
    }  
    else // 没有该文件  
    {  
        cout <<"no such file" << endl;  
    }  
  
    return 0;  
}  

https://www.cnblogs.com/huojing/articles/5665923.html

猜你喜欢

转载自blog.csdn.net/qq_35608277/article/details/86743659