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

Help Please with my While Loop

I working on a program and I using a while loop. My while loop has to read information from a file. the file contains three lines with names, and a bunch of numbers and dates.

the problem that I am having is that my the program is not reading the dates

which are month/day/year
how can i fix that to make the dates apear.
heres is what i have:

#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
#include <cmath>



using namespace std;

int main()
{


int month;
int day;
int year;
char junkChar;

string sampleInput;

ifstream inFile;
inFile.open("F:\\people.txt");



while(!inFile.eof())
{


inFile>> sampleInput;
getline(inFile,sampleInput,'\n');



if ( sampleInput=="")
{
cout << endl;


}
else
cout << sampleInput << endl;



}
cout << endl;


inFile.close();

return 0;
}
Oct 16 '08 #1
1 1321
boxfish
469 Expert 256MB
It's not working because of these two lines:
Expand|Select|Wrap|Line Numbers
  1. inFile>> sampleInput;
  2. getline(inFile,sampleInput,'\n');
  3.  
You're reading the date into sampleInput with the >> operator, and then reading what's left of the line (possibly nothing) right over it with getline, erasing the date. If you want the whole line to be read, including whitespace characters, use only getline. If you want to allow multiple dates per line, and to read in anything separated by whitespace as separate dates, use only >>. If you want to read in only one date per line without whitespace and ignore the rest of the line, use >> and then getline ino a dummy string:
Expand|Select|Wrap|Line Numbers
  1. inFile>> sampleInput;
  2. getline(restOfLine,sampleInput,'\n');
  3.  
If you want to speak to an operator, press 1. If you want to hear about code tags, press 2.
When you post code, please use code tags. Put [CODE] before the code and [/CODE] after it so it shows up in a code box and the indentation isn't wrecked. Thanks.
Hope this helps.
Oct 17 '08 #2

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

Similar topics

23
by: Jason | last post by:
Hi, I was wondering if any could point me to an example or give me ideas on how to dynamically create a form based on a database table? So, I would have a table designed to tell my application...
3
by: mslyman | last post by:
Hi, I could do with some help. I have this XML. <region> <region_code>567</region_code> <store> <store_code>345</store_code> <dept> <dept_code>32</dept_code> </dept>
1
by: Benton2862 | last post by:
I need help with and array for a program that acts like a cash register. The user will input an items price and then there payment. It will tell you the change and then tell you what kinda of change...
28
by: Nutkin | last post by:
Basicly i have to make a program that calculates the distance between x and y points in 2d space. the code basicly goes like this 1. User says how many points they have (max of 10) 2. User...
1
by: al2004 | last post by:
Write a program that reads information about youth soccer teams from a file, calculates the average score for each team and prints the averages in a neatly formatted table along with the team name....
1
by: ndawg123 | last post by:
Hey guys what im trying to do is write a yatzee game with C. And im stuck already and its the start?!?! I want the user to type there 5 numbers. i.e My program so far does this Please...
9
by: TF | last post by:
Hello all, I made a ASP.NET 2.0 site that shows possible "recipes" for paint colors stored in an access dbase. Basically, 1000 colors are stored with specific RGB values in separate columns. A...
6
by: jenipriya | last post by:
Hi all... its very urgent.. please........i m a beginner in oracle.... Anyone please help me wit dese codes i hv tried... and correct the errors... The table structures i hav Employee (EmpID,...
0
by: shrik | last post by:
I have following error : Total giant files in replay configuration file are : File name : /new_file/prob1.rec Given file /new_file/prob1.rec is successfully verified. Splitting for giant file...
3
by: gmdune | last post by:
Hi All, I have written a program that doesn't seem to work and I can't figure out why it's not working. It compiles correctly, but when I run it I get prompted by the first couple of printf...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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: 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
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: 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...

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.