473,399 Members | 2,858 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,399 software developers and data experts.

I having issues with My While LOOP please help

i working on a program in c++ and my program is to read data from a file. I using a while loop.
the while loop is not reading the dates of each line. mm/dd/yyyy

everything in the file is reading accept the begining of each line which starts with the date. How do i fix it to make the program read the whole file.


Expand|Select|Wrap|Line Numbers
  1.  
  2. #include <iostream>
  3. #include <iomanip>
  4. #include <string>
  5. #include <fstream>
  6. #include <cmath>
  7.  
  8.  
  9.  
  10. using namespace std;
  11.  
  12. int main()
  13. {
  14.     int month;
  15.                 int day;
  16.                 int year;
  17.                 int junkChar;
  18.  
  19.  
  20.  
  21.     string sampleInput;
  22.  
  23.     ifstream inFile;
  24.     inFile.open("F:\\data3.txt");
  25.  
  26.  
  27.  
  28.     while(!inFile.eof())
  29.     {
  30.  
  31.  
  32.         inFile>> sampleInput;
  33.         getline(inFile,sampleInput,'\n');
  34.  
  35.  
  36.  
  37.         if ( sampleInput=="")
  38.         {
  39.             cout << endl;
  40.  
  41.  
  42.         }
  43.         else
  44.             cout << sampleInput << endl;
  45.  
  46.  
  47.  
  48.     }
  49.         cout << endl;
  50.  
  51.  
  52.         inFile.close();
  53.  
  54.         return 0;
  55. }
  56.  
  57.  
Oct 17 '08 #1
4 1215
JosAH
11,448 Expert 8TB
Hi, I deleted your other identical thread. If you think your thread needs a bit more
attention simply *bump* it by replying to your own thread so it ends up at the top
of the list again. Please don't double post your questions.

kind regards,

Jos (moderator)
Oct 17 '08 #2
donbock
2,426 Expert 2GB
i working on a program in c++ and my program is to read data from a file. I using a while loop.
the while loop is not reading the dates of each line. mm/dd/yyyy

everything in the file is reading accept the begining of each line which starts with the date. How do i fix it to make the program read the whole file.
I don't understand. Are you saying that your program correctly reads every line of the file but somehow doesn't see the first few characters of each line? If so, then there isn't anything wrong with your while-loop; the problem is with how you parse the input lines.

As an experiment, don't try to parse the input lines at all, simply write them out again. Does that program print out a copy of the input file?
Oct 17 '08 #3
boxfish
469 Expert 256MB
I thought I already answered this question.
Oct 17 '08 #4
donbock
2,426 Expert 2GB
I thought I already answered this question.
Sorry -- must have been on that other identical thread.
Oct 18 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Markku Uttula | last post by:
I think I'm doing something wrong. I'm able to connect to Oracle just fine, execute queries and all, but I'm having serious problems with the speed :( For example, the following PHP-script on my...
2
by: shblack | last post by:
I need help with a program I am writing for school. The program has to do the following: /* 1. Character string must be a minimium of 15 charactors. 2. If not 15 characters long it must give...
1
by: Klauer | last post by:
Hello all, I'm kind of new to working with C++, and I have an issue in solving an issue that maybe someone out here can help me with. I have a piece of code in this project that I'm tasked to...
3
by: =?Utf-8?B?QXhlbCBEYWhtZW4=?= | last post by:
Hi, we've got a strange problem here: We've created an ASP.NET 2.0 web application using Membership.ValidateUser() to manually authenticate users with our website. The problem is: If the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
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.