C++, files

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

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
 
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!
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

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 807,865 other people just like you!

Latest posts

Members online

Top