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

ifstream --- error maybe?

I wrote a piece of code that reads read in about 1000 int values from
a text file. I put a cout statement to verify that the input in the
code was working as anticipated. It seems to work fine until some
point when it just ouputs 0's. So I then took the code and made a app
that just read the file and it worked fine.

Does anyone have a suggestion.

Jason
Jul 22 '05 #1
3 1241
> I wrote a piece of code that reads read in about 1000 int values from
a text file. I put a cout statement to verify that the input in the
code was working as anticipated. It seems to work fine until some
point when it just ouputs 0's. So I then took the code and made a app
that just read the file and it worked fine.

Does anyone have a suggestion.


Reduce the code to the smallest amount that still produces the problem and
post that code.

Niels Dybdahl
Jul 22 '05 #2
Jason wrote:
I wrote a piece of code that reads read in about 1000 int values from
a text file. I put a cout statement to verify that the input in the
code was working as anticipated. It seems to work fine until some
point when it just ouputs 0's. So I then took the code and made a app
that just read the file and it worked fine.

Does anyone have a suggestion.


Yes. Post the code. We are programmers, not clairvoyants.

- J.
Jul 22 '05 #3
On 27 Oct 2004 20:36:58 -0700, js*******@gmail.com (Jason) wrote:
I wrote a piece of code that reads read in about 1000 int values from
a text file. I put a cout statement to verify that the input in the
code was working as anticipated. It seems to work fine until some
point when it just ouputs 0's. So I then took the code and made a app
that just read the file and it worked fine.

Does anyone have a suggestion.


How are you checking for the end of the input? You should do something
like this:

int i = 0;
for(; i != 1000; ++i)
{
int val;
if (!(stream >> val))
break;
//assign val to whatever
}

if (i < 1000)
{
//something went wrong
//check stream.eof(), stream.bad() and stream.fail().
}

Tom
Jul 22 '05 #4

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

Similar topics

6
by: Herv? LEBAIL | last post by:
Hi everybody, I'm writing a program which use the <string>, <vector> and <ifstream> classes. Given an array of string, i.e vector<string> file_names, example : file_names = "file1.txt"...
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"...
4
by: hall | last post by:
Hi. I ran across a bug in one of my problems and after spending some time tracking it down i found that the problem arose in a piece of code that essentially did this: ----------- ifstream...
10
by: sam | last post by:
Hi, Can anyone tell me how to print a file name from ifstream? the following cout code does not print the filename I created with ifstream preivous: ifstream is; is.open ("text.txt");
8
by: ambar.shome | last post by:
Hi, We are working on Solaris SunOS 5.8. We are using ifstream of iostream namespace. The snippet is given below: #include <iostream.h> #include <fstream.h> boolean readFile() { char...
2
by: Massimo Soricetti | last post by:
Hello, I'm trying to fix this little class: <code> #include <ifstream> #include <iostream> #include <iomanip> using namespace std;
4
by: marathoner | last post by:
I tried your advice, and replaced "ifstream" with "std::ifstream". I also replaced instances of "ofstream" with "std::ofstream". Those syntax errors were resolved. When I added "std" to the...
6
by: Gary Wessle | last post by:
hi I have a code, the part which is troubling goes like this **************************************************************** #include <istream> #include <ostream> #include <fstream>
4
by: uche | last post by:
Hello, I am having a problem with my code in C++/C. I have struggled for a while and cannot find the solution to the problem... Here is the compiled..output: In file included from disk.cpp:8:...
11
by: adramolek | last post by:
So... I'm trying to get used to using C++ ifstream (or ofstream) instead of stdio (although I'm having second thoughts). Anyways, I want to be able to display a meaningful error message if ifstream...
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:
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.