1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

C++, files

Discussion in 'Software Development' started by calculus87, Sep 24, 2003.

Thread Status:
Not open for further replies.
  1. calculus87

    calculus87 Thread Starter

    Joined:
    Sep 4, 2003
    Messages:
    34
    I have a question for yall,
    I would like to read from a file. Now I would like to read only one line. I would like to read that line string by string until that one line is done. I would then like to exit.
    Okay, now here is what is done.
    I can read from a file.
    I know how to read one string at a time, and I know how to read in an entire line using getline()
    I can exit

    I am not sure how to use the >> command to only read string by string for one line.

    I was trying something like

    string a;
    input2.open("out123456789.txt");
    while (a!=eol)
    input2>>a;

    Thanks for the help
    Hopefully I have made myself clear.

    Sincerely,
    Ronald
     
  2. Regicide

    Regicide

    Joined:
    Aug 8, 2003
    Messages:
    307
    You can use the command getline() in string.h. For example:
    Code:
    char szBuffer[30];
    ifstream File;
    file.open("blah.txt");
    file.getline(szBuffer, 25, " ");
    
    This way, it stores a word sperated by a space. Hope this works!
     
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/167087

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice