fstream vs FILE

S

solarrobor

I am currently porting a program from C to C++. The program needs to
read the file "/proc/bus/usb/devices".
I am able to open and read from the file using FILE but not when I use
fstream.

Why does it work with FILE and not fstream?
What is the solution to making it work using fstream?

I am using GCC 4.2.3 on Fedora 8
 
V

Victor Bazarov

solarrobor said:
I am currently porting a program from C to C++. The program needs to
read the file "/proc/bus/usb/devices".
I am able to open and read from the file using FILE but not when I use
fstream.

Why does it work with FILE and not fstream?

Because in your fstream use there is a logical error on line 42.
What is the solution to making it work using fstream?

The solution is usually to fix the problem. Since you didn't tell
us what the problem actually is, how can we help you fix it?

Another possible solution is not to do anything, just keep using
FILE pointers and you should be OK.

V
 
C

Christopher

Because in your fstream use there is a logical error on line 42.


The solution is usually to fix the problem. Since you didn't tell
us what the problem actually is, how can we help you fix it?

Another possible solution is not to do anything, just keep using
FILE pointers and you should be OK.

V


I have to disagree, Victor. My crystal ball is bigger and shinier and
it says it is line 63.
 
V

Victor Bazarov

Christopher said:
solarrobor said:
I am currently porting a program from C to C++. The program needs to
read the file "/proc/bus/usb/devices".
I am able to open and read from the file using FILE but not when I
use fstream.
Why does it work with FILE and not fstream?

Because in your fstream use there is a logical error on line 42.
[..courtesy snip of overquoted material..]

I have to disagree, Victor. My crystal ball is bigger and shinier and
it says it is line 63.

Apparently your ball is bigger by exactly 50%... <g>

V
 
P

Paavo Helde

I am currently porting a program from C to C++. The program needs to
read the file "/proc/bus/usb/devices".
I am able to open and read from the file using FILE but not when I use
fstream.

Porting C to C++ involves providing function declarations in header files
and some more obscure changes. The FILE* interface is perfectly OK in C++,
so it seems you are probably wasting your employer's money ;-)

NHTH (not hoping this helps... )
Paavo
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

fstream File i/o 1
fstream Buffers 26
fstream -> FILE* 1
Error reason for fstream failures 5
fstream vs ofstream 6
fstream 6
eof error using '>>' in fstream 2
[c++] get() and read() function from fstream 3

Members online

Forum statistics

Threads
473,778
Messages
2,569,605
Members
45,238
Latest member
Top CryptoPodcasts

Latest Threads

Top