How do I read a text file from the second line using fstream?

后端 未结 8 1664
野趣味
野趣味 2020-12-31 03:19

How can I make my std::fstream object start reading a text file from the second line?

8条回答
  •  粉色の甜心
    2020-12-31 03:56

    #include 
    #include 
    #include 
    
    using namespace std;
    
    int main()
    {
    string textString;
    string anotherString;
    ifstream textFile;
    textFile.open("TextFile.txt");
    if (textFile.is_open()) {
        while (getline(textFile, textString)){
            anotherString = anotherString + textString;
        }
    }
    
    std::cout << anotherString;
    
    textFile.close();
    return 0;
    }
    

提交回复
热议问题