473,382 Members | 1,369 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Problem with ifstream

I do something like this:

ifstream file(argv[1]); if(!file) //...
file.read(buffer,BUFFSIZE);
while(!file.eof())
{
for(int i=0; i<BUFFSIZE; i++)
// ...

file.read(buffer,BUFFSIZE);
}
int nlastread=file.gcount();
for(int i=0; i<nlastread; i++)
// ...

And then things like these don't work;

file.seekg(0); // file.tellg() is -1
file.seekg(20) // file.tellg() is still -1
file.close(); file.open(argv[1]) // Can't open: !file is true.
the only way to do it I've found is:

ofstream file2(argv[1]);

but I'm not very keen on that solution.

What do you think?

Jul 22 '05 #1
0 972

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: pentiumPunk | last post by:
string fileName; cout<<"Enter filename of datafile you wish to open \n"; cin>>fileName; ifstream fin; fin.open(fileName, ifstream::ios); if(!fin) {
3
by: nadz | last post by:
just looking at this main int main() { ifstream fin("text.txt"); doStuff(fin); //processes the data from text.txt fin.close(); fin.open("text2.txt"); doStuff(fin); //processes the data from...
7
by: Anton Ishmurzin | last post by:
Greetings All, I think everybodyknows the answer already. But i am quite a newbie in c++. I've got the following line in my code: ifstream ini_file_in("filename.dat", ios::in); But, the...
6
by: Ram Laxman | last post by:
Iam new bie to C++ programming.. I want to write a program which will read the Comma separated values(CSV) file column wise. For example: In a.txt: "TicketNumber","Phone","CarNumber"...
3
by: Mike Alexeev | last post by:
Hi all, I have come across very strange behavior of the return value of the time() function. Below is the program to illustrate the problem: The value of NOW somehow changes after the call to the...
4
by: jared.oconnell | last post by:
Howdy, I am having a weird problem with ifstream. ifstream img; img.open(im_fn.c_str(),ios::in|ios::binary); char *x = new char; if(!img) { cerr << "Error: problem reading img" << endl;...
2
by: merrittr | last post by:
I have a small program to read data from some data files , in it I use string types to build the data file name but when I try to compile it I get: (see code below error) ...
1
by: SantaClaus | last post by:
Hi all, Im getting an exception in the middle of reading a file and here is my code std::ifstream inf; const int bufSize=1024; char tbuffer; std::string filex = path; // may be C:\test.txt const...
3
by: waynejr25 | last post by:
can anyone debug my program and get it to run. #include <fstream> #include <iostream> #include <string> #include <cstdlib> #include <map> using namespace std;
9
by: aemado | last post by:
I haven't written basic array code in so long, I have forgotten how to do some of it. I have two data files. There is some data that is common to both, and some that is only in the first and not the...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.