searching for a word in txt and copying a line from it to another txt

Hello
Newbie here, so be gentle please :D
I have a txt file which contains this.
Mass Flow Rate = 1.06978
Total Press Ratio = 1.05436
Adiabatic Efficiency = 0.729592
Exit Flow Coeff Cr2/U2rms = 0.437959
Ps2/Pa = 0.990665
I want to read the 3rd line only and copy it into another txt file and put it in the middle of it.

What is the best way to do that
Just point me to the right direction, which function should i use


Answer this question

searching for a word in txt and copying a line from it to another txt

  • Chase Mosher

    sorry I tried editing my post but it keeps giving me errors

    anyway here's my code

    it doesn't seem to work

    I was thinking about reading it into a string first

    #include <fstream>

    #include <iostream>

    #include <string>

    using namespace std;

    void main()

    {

    string c;

    ifstream reads("R0_1st.txt");

    reads.seekg(ios::beg);

    reads.unsetf(ios::skipws);

    reads>>c;

    cout<<c;

    }


  • EntitySpaces

    You can use getline function to read each line of a text file

  • DennisW511

    Sorry again...

    can someone please tell me why it won't let me edit my post !!

    anyway here's the new code

    it works but i need to add to that, i want it to only display the line if this string is found "Adiabatic Efficiency = 0.729592"

    how do i do that

    #include <fstream>

    #include <iostream>

    #include <string>

    using namespace std;

    void main()

    {

    string c;

    ifstream reads("R0_1st.txt");

    reads.seekg(ios::beg);

    reads.unsetf(ios::skipws);

    while(!reads.eof())

    {

    getline (reads,c);

    cout<<c<<endl;

    }

    }


  • searching for a word in txt and copying a line from it to another txt