CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2005
    Posts
    120

    problem reading file

    hi,

    i have a program that is supposed to read the first line (the only one ) from a text file and pass it as the argument for a process using create process. problem is here:

    char str[2000];
    fstream file_op("test.txt",ios::in);
    file_op >> str;
    cout << str;


    i was first testing and for some reason i dont get all the text on that line.. only the first segment .. (it is becuase the line has spaces in it) so if it said: one two. it would only print one. any suggestions on how i can accomplish this ?

    thanks

  2. #2
    Join Date
    Aug 2000
    Location
    West Virginia
    Posts
    7,725

    Re: problem reading file

    Code:
    fileop.getline(str,1999);
    you might consider reading inti a std::string instead, that way you
    do not have to worry about the 2000 or 1999 numbers.

  3. #3
    Join Date
    Feb 2005
    Posts
    120

    Re: problem reading file

    thanks alot! that worked.. how can i grab the 2nd line ?

  4. #4
    Join Date
    May 2004
    Location
    Norway
    Posts
    655

    Re: problem reading file

    Do it again.
    Insert entertaining phrase here

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured