Thread: File Reading Problem

  1. #1
    Registered User
    Join Date
    Mar 2005
    Posts
    1

    File Reading Problem

    Hello, everyone. Like to thank all those who took the time to look at this thread. I'm in need of some assitance. I'm trying to get a program to read from the second line instead of the first line of a txt file. Here is what I have so far:

    Code:
    
    #include <iostream.h>
    #include <fstream.h>
    int main()
    {
      char a[200];
      ifstream inFile("a:\\joey.txt", ios::in);
      inFile.get(a,200);
      cout<<a<<endl;
      inFile.close();
      }
    
    That makes it get from the first line. But everything I've tried to make it read from the second instead, hasn't worked. So can anyone help me out?

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    184
    the post what u have done is not relavent to this board. this is 'C' board form.

    s.s.harish

  3. #3
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    Moved to C++ board.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  4. #4
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    try this:
    Code:
    #include<iostream>  //standards-compliant header
    #include<fstream>   //same as above
    
    int main()
    {
        char*line=new char&#091;256&#093;;
        std::fstream file("Untitled1.dat",std::ios::in);
        file.ignore(32000,'\n');        //ignore 32k chars, or up to '\n'
        file.getline(line,256,'\n');    //take in the next line, up to 256 chars
        std::cout<<line;                //output the line
        std::cin.get();                 //wait for user input
        return 0;
    }
    Last edited by major_small; 03-30-2005 at 10:51 AM. Reason: commentation
    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. File transfer- the file sometimes not full transferred
    By shu_fei86 in forum C# Programming
    Replies: 13
    Last Post: 03-13-2009, 12:44 PM
  2. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  3. Replies: 20
    Last Post: 06-12-2005, 11:53 PM
  4. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  5. Problem reading file
    By winsonlee in forum C Programming
    Replies: 2
    Last Post: 04-23-2004, 06:52 AM