Reading multiple lines from a file

This is a discussion on Reading multiple lines from a file within the C++ Programming forums, part of the General Programming Boards category; Hi, all! I'm writing an encryption program where I want to encrypt 2 lines that are being read in from ...

  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    9

    Reading multiple lines from a file

    Hi, all!

    I'm writing an encryption program where I want to encrypt 2 lines that are being read in from a file. First I want to encrypt the 1st line and write the encrypted version to a second file. Then I want to encrypt the 2nd line and write it to a third file.

    How can I read in the 2 lines so that I can deal with each one individually?

    e.g. this is line one
    this is the second line.

    I want to read in line 1, encrypt it, and send it to a second file. Then I want to read in line 2, encrypt it, and send it to a third file.

    some version of get(), getline() ???

    HELP PLEASE???

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    One solution is std::getline() and a string object.

    Kuphryn

  3. #3
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    cin.getline() for c-style strings
    getline() for string objects

  4. #4
    Wen Resu
    Join Date
    May 2003
    Posts
    219
    convert first line char by char until it hits EOL character #10 and #13 if memory servers <those are ANSI> at which point have it output to second file

  5. #5
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    file2.getline(string,[int],'\n');
    file3.geline(string,[int],'\n');
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 02-02-2009, 07:27 AM
  2. Reading lines from a File
    By DivineSlayer936 in forum C++ Programming
    Replies: 12
    Last Post: 04-02-2007, 01:12 PM
  3. Line Counting
    By 00Sven in forum C Programming
    Replies: 26
    Last Post: 04-02-2006, 09:59 PM
  4. Problems in reading binary file
    By serena in forum C Programming
    Replies: 3
    Last Post: 04-14-2005, 04:54 AM

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