December 7th, 2004, 12:53 AM
|
#1 (permalink)
| | Member
Join Date: Nov 2004
Posts: 56
|
what does this do?, while (! fin.eof). i wrote it in my notes but forgot why i wrote it down. please give detailed explanation if possible. |
| |
December 7th, 2004, 01:08 AM
|
#2 (permalink)
| | Fur ballin
Join Date: Oct 2001 Location: Victoria, BC
Posts: 4,371
| |
| |
December 7th, 2004, 01:09 AM
|
#3 (permalink)
| | Fur ballin
Join Date: Oct 2001 Location: Victoria, BC
Posts: 4,371
| |
| |
December 7th, 2004, 01:09 AM
|
#4 (permalink)
| | I am a banana!
Join Date: Jun 2002 Location: Texas Tech
Posts: 3,921
|
it just keeps looping until the end of a file has been found. Technically the while loop waits until the eof (end of file) character has been read. It's part of the standard library. |
| |
December 7th, 2004, 01:47 AM
|
#5 (permalink)
| | Member
Join Date: Nov 2004
Posts: 56
|
sorry, i was not specific enough, it is c++, and i know that if loops till the end of the file, i suppose i need like a simple example if possible. |
| |
December 7th, 2004, 10:45 AM
|
#6 (permalink)
| | I am a banana!
Join Date: Jun 2002 Location: Texas Tech
Posts: 3,921
| Code: void main()
{
ifstream fin;
char stuff;
fin.open("myfile.txt");
while(!fin.eof)
fin>>stuff;
fin.close();
} |
| |
December 7th, 2004, 11:15 AM
|
#7 (permalink)
| | Ultimate Member
Join Date: Oct 2003 Location: Aztec, New Mexico
Posts: 1,608
|
You can use a variation of it to check if the file is there:
ifstream inFile(file.txt);
if(! inFile)
{
cout << "File not found" << endl;
} |
| |
December 7th, 2004, 11:32 AM
|
#8 (permalink)
| | Member
Join Date: Nov 2004
Posts: 56
|
void main()
{
ifstream fin;
char stuff; //could this be used to get number values too
fin.open("myfile.txt"); //or is it just for char.
while(!fin.eof)
fin>>stuff; //could i fin multiple values like fin>>num1>>num2
fin.close(); //and would can if so could the num1 be an int and
} //num2 be a float.
i'm working on a program and we are supposed to call a function to read two values 1st one is an int and 2nd one is a float. but we can only use a one line call routine two get both numbers, and i dont know what type to make the function because its returning both an int and a float.
also when i call the function i dont know how to make it equal both numbers like
employeeid=data_in(fin); //both id and sales are supposed to come from data_in
sales=data_in(fin); //id is an int and sales is a float but who knows how
//you do that. |
| |
December 7th, 2004, 11:55 AM
|
#9 (permalink)
| | Ultimate Member
Join Date: Oct 2003 Location: Aztec, New Mexico
Posts: 1,608
|
C++ will read until it encounters a space or a tab, then skip to the next input variable, if one exists in the input statement.
If you declare an int object X, and a string object Y, and type:
inFile >> X >> Y
it will assign the integer value found at the beginning of the file to X, and the string object found after, to Y. |
| | |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | | |
Posting Rules
| You may post new threads You may post replies You may not post attachments You may not edit your posts HTML code is Off | | | | Most Active Discussions | | | | | Recent Discussions  | | | | | |