File IO (txt file)

This is a discussion on File IO (txt file) within the C++ Programming forums, part of the General Programming Boards category; How do I read information from a certain line from a txt file in as a char, and then edit ...

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    44

    Arrow File IO (txt file)

    How do I read information from a certain line from a txt file in as a char, and then edit it.

    This my code, but it doesn't work? Can someone please help as File IO is one of my weaker areas of C++..

    Code:
      char replacement[10];
        int x;
        int lines =;
        char buffer[256];
    
         cout << "Please Enter the line you would like to edit: ";
         cin >> x;
         endl;
         cout << "Line " << x << " curently reads ";
         endl;
         ifstream afile (managerfile);
         afile.getline (buffer,100);
         while(afile.getline (buffer,100))
           {
            if(lines==x) cout << buffer;
            else cout << "Line " << x << " does not exsist";
           }
         afile.close();
    	endl;
         cout << "Replace with: ";
         cin >> replacement;
         endl;
         ofstream bfile (managerfile, ios::app);
           while(bfile.getline (buffer,100))
           {
            if(lines==x);
            bfile<<replacement;
           }
         bfile.close();
         cout<<"Line Succesfully Edited";
    Also can someone explain what the 100 after (buffer, is refering to?

    Thanks.
    I'm using Bloodsheds Dev-C++ Compiler.

    JamMan..

    Curious if I can live forever? CLICK HERE

  2. #2
    Lead Moderator kermi3's Avatar
    Join Date
    Aug 1998
    Posts
    2,595
    There is LOTS of information on this topic on the FAQ board, and a comprehensive tutorial to this in the tutorials section of the main site.

    http://www.cprogramming.com/tutorial.html
    Kermi3

    If you're new to the boards, welcome and reading this will help you get started.
    Information on code tags may be found here

    - Sandlot is the highest form of sport.

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    44
    Cheers Kermi

    But I've read through the tutorials about file io and search the net but cann't find any info on how to goto to specific line in a txt file and then edit it??

    I'm using Bloodsheds Dev-C++ Compiler.

    JamMan..

    Curious if I can live forever? CLICK HERE

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie homework help
    By fossage in forum C Programming
    Replies: 3
    Last Post: 04-30-2009, 05:27 PM
  2. Inventory records
    By jsbeckton in forum C Programming
    Replies: 23
    Last Post: 06-28-2007, 05:14 AM
  3. Encryption program
    By zeiffelz in forum C Programming
    Replies: 1
    Last Post: 06-15-2005, 04:39 AM
  4. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 11:12 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21