Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old May 3, 2005, 12:06 PM   #1
Beckie
macrumors newbie
 
Join Date: Apr 2005
input file with multiple types of data types

Hi
I have an input file that I need to infile into my program:

Joe smith 23
alice west 45
bob MILLS 82
*
45 182 210 43 170 301 -1
82 150 97 -220 178 223 300 -1

I can get the names and the numbers after the names in, but when I get to
the asterisk, the computer thinks * is a string instread of a char, and then it skips 45 and 182 and then I can get 210, 43, etc as int data types, but the 45 and 182 are coming up as string data types.

Here is how I am doing it:

while(infile)
{
if (firstname != "*")
{
infile >> firstname >> lastname >> leagueIDnum;
cout << firstname << lastname << leagueIDnum << endl;
}

if(firstname == "*")
{
infile >> bowlingscores;
cout << bowlingscores << endl;
}
}
Beckie is offline   0 Reply With Quote
Old May 5, 2005, 08:48 AM   #2
whooleytoo
macrumors 603
 
whooleytoo's Avatar
 
Join Date: Aug 2002
Location: Cork, Ireland.
Send a message via AIM to whooleytoo
Quote:
Originally Posted by Beckie
Hi
while(infile)
{
if (firstname != "*")
{
infile >> firstname >> lastname >> leagueIDnum;
cout << firstname << lastname << leagueIDnum << endl;
}

}
I'm afraid this bit will never work. You read in the first, last names and league ID all at once, so by the time you've read in the "*", the program has already read ahead looking for lastname and leagueID.

If you can change the input data, replace "*" with "* * *"? This would be the easiest fix.

Otherwise, you could change the code to something like:

Code:
firstname = "" ;

while (firstname != "*")
{
    infile >> firstname ;
    if (firstname != "*")
    {
        infile >> lastname >> leagueIDNum ;
        cout << firstname << lastname << leagueIDnum << endl;
    }
}
.
.
.
(Of course, to be correct you should also be checking for the end-of-file, or handling exceptions in case the input file is incomplete or improperly formatted.)

Hope this helps!
__________________
Mac <- Macintosh <- McIntosh apples <- John McIntosh <- McIntosh surname <- "Mac an toshach" <- "Son of the Chief"
whooleytoo is offline   0 Reply With Quote
Old May 5, 2005, 12:02 PM   #3
Beckie
Thread Starter
macrumors newbie
 
Join Date: Apr 2005
Thank you so much! This helps me so much. This is exactly what I was looking for.

Take care,
Beckie
Beckie is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
Framerate problem with XSplit, League of Legends, & BOOTCAMP on 2011 Macbook Pro superkrups20056 Mac and PC Games 0 Oct 11, 2011 06:42 PM
Typing Paratroopers - typing games can't get more addictive than this sparkso iPhone and iPod touch Apps 1 Aug 6, 2011 09:56 AM
How can I view the amount of space each type of data is taking up? dvader123 MacBook Pro 1 Sep 5, 2010 03:17 PM
Installing multiple types of OS on one disk BreuerEditor OS X 4 Sep 9, 2009 12:45 PM
Multiple Types of Bullets & Numbering in One List rs7 Mac Applications and Mac App Store 0 Jan 15, 2009 04:59 PM


All times are GMT -5. The time now is 07:54 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

Privacy / DMCA contact / Affiliate and FTC Disclosure
Copyright 2002-2013, MacRumors.com, LLC