|
-
Nov 4th, 2002, 03:17 PM
#1
Thread Starter
<?="Moderator"?>
keep printing lst char
Code:
#include <iostream>
#include <fstream>
using namespace std;
int main(int argc, char * argv[])
{
if(argc<2)
{
cout<<"The correct format is file <string>"<<endl;
return 0;
}
cout<<"correct number of parimeters."<<endl;
cout<<"You have "<<argc<<" parimeter"<<endl;
for(int x=0;x<argc;x++)
{
cout<<argv[x]<<endl;
}
if(argc>2)
{
if(argv[1]="open")
{
ifstream a_file;
a_file.open(argv[2]);
char x;
a_file.get(x);
while(x!=EOF)
{
cout<<x;
a_file.get(x);
}
a_file.close();
}
}
return 0;
}
all of the code works, apart from the fact that it keeps printing out the last character in the text file.
-
Nov 5th, 2002, 04:45 AM
#2
AFAIK ifstream::get() never retrieves the EOF character. Use ifstream::eof() to test for the end-of-file condition instead.
Code:
a_file.open(argv[2]);
char x;
a_file.get(x);
while(!a_file.eof())
{
cout<<x;
a_file.get(x);
}
a_file.close();
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Nov 5th, 2002, 04:45 AM
#3
This might eat the last character of the file, maybe you have to reorder the code.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Nov 5th, 2002, 12:32 PM
#4
Thread Starter
<?="Moderator"?>
thanks its working great
btw, it didnt eat the last character.
Thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|