473,394 Members | 1,840 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,394 software developers and data experts.

fstream vs FILE

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
Mar 7 '08 #1
4 3276
solarrobor wrote:
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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Mar 7 '08 #2
On Mar 7, 12:04 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
solarrobor wrote:
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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask

I have to disagree, Victor. My crystal ball is bigger and shinier and
it says it is line 63.
Mar 7 '08 #3
Christopher wrote:
On Mar 7, 12:04 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
>solarrobor wrote:
>>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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Mar 7 '08 #4
solarrobor <fr*********@yahoo.co.ukwrote in news:e886828b-d88b-4eee-8f71-
fe**********@n77g2000hse.googlegroups.com:
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
Mar 18 '08 #5

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

Similar topics

3
by: David Blasdell | last post by:
This appears very strange to me, I'm having a problem with a fstream object inside a class which is not being called directly from main (another class calls the class that contains the fstream...
2
by: NewToCPP | last post by:
I am having some trouble including "iostream" "fstream" to my code. I tried the following ways and base times it did not work. What is the problem? test.cc: ======= ..... #include...
9
by: Someonekicked | last post by:
In my program, I need to open multiple files, and I wont know till after the program execution how many of them (user will enter that value). So I am using a vector of fstream. I am using fstream...
6
by: wiso | last post by:
My problem is this (from: http://www.cplusplus.com/ref/iostream/fstream/open.html) #include <fstream> using namespace std; int main() { fstream f;
2
by: jjcp | last post by:
I would like to say thanks in advance for insight anyone can shed on this for me. Long story short from time to time I need to us C++ to take a list of file and make an index out of them in...
5
by: neowillis | last post by:
code: #include <iostream> #include <fstream> #include <string> using namespace std; int main() {
7
by: Soneji | last post by:
*sigh* Ok, I have two questions. First, my setup: Win-doze XP-SP2; & Dev-C++ 4.9.9.2; I recently started trying to use 'fstream' to work my input/output, and I noticed that using the...
6
by: Gaijinco | last post by:
Should this do something? #include <fstream> #include <string> int main() { std::fstream filestr ("test.txt", std::fstream::in | std::fstream::out); std::string s="";
3
by: Ioannis Vranos | last post by:
Hi, I am experimenting with fstream type, I have written the following code: #include <iostream> #include <fstream> #include <string> int main() { using namespace std;
1
by: Sachin Garg | last post by:
I have a program which opens a fstream in binary input+output mode, creating the file if it doesn't exists. But writing doesn't works after reading, it must be something obvious that I am not aware...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.