Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <iostream>
- #include <string>
- using namespace std;
- int main(int argc, char* argv[])
- {
- string s[255];
- ifstream in("in.txt"); // Opening a file for reading
- cout<<"Enter number"<<endl;
- string n;
- cin>>n;
- int num = NULL;
- for (int i = 0; i < n.length(); i++){
- num = num*10 + n[i] - 0x30; //Convert the entered number to a number
- }
- int i = 1;
- while(getline(in,s[i]))// Read the line from the file
- i++;
- in.close(); //Closed the file
- if (num < i)
- s[num] = s[num] + " " + n ; //We add the number after the required line
- ofstream of("in.txt"); //Opened the file for writing
- for ( int j = 1; j < i; j++)
- {
- of<<s[j]; //Writing lines to a file
- of<<endl;
- }
- of.close(); // Close the file
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement