Reading line by line in c++

Discussion in 'Programming' started by Anirudh.Mehta, Feb 21, 2009.

  1. #1
    Hi..!!
    I was creating a program but now i am stuck. Please help me.
    I want to read from .txt file.
    Contents of txt file :-
    1)number- no. of lines
    2)line 1
    3)line 2
    and so on

    I want to read this file line by line and save in string str[n]
    First line will give me integer value n;
    then rest of lines should be stored in str[1],str[2] and so on..

    I tried to do this using null character but not working.
    Please help me.
     
    Anirudh.Mehta, Feb 21, 2009 IP
  2. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #2
    char *mystring[];
    mystring = new char[][n];

    Not sure if that works, try it. I know without [] it will work thou.

    Peace,
     
    Barti1987, Feb 21, 2009 IP
  3. Hackcool

    Hackcool Peon

    Messages:
    17
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    char *mystring[];
    mystring = new char[][n];

    Not sure if that works, try it. I know without [] it will work thou.

    Peace,
     
    Hackcool, Feb 21, 2009 IP
  4. it career

    it career Notable Member

    Messages:
    3,562
    Likes Received:
    155
    Best Answers:
    0
    Trophy Points:
    270
    #4
    Does not seem to be C++ syntax.
     
    it career, Feb 22, 2009 IP