C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old May 22nd, 2003, 10:35 PM
rpgwh rpgwh is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2003
Posts: 2 rpgwh User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Exclamation AP Computer Science Help - Structs

I have these two structs

struct BookInfoType
{
apstring Title;
apstring Author;
apstring ISBN;
apstring PubName;
int PubYear;


};

struct Book
{
int number;
apvector<BookInfoType> list;

};

the problem comes when I try to enter the data (which is in a text file with spaces in the name such as Mr. John etc.) how do I use the getline thing in struct to ignore spaces. so far I have this:

void getData(Book &data)
{
ifstream infile("data.txt", ios::in);

infile >> data.number;

data.list.resize(data.number);


int i = 0;

while((!infile.eof() && i < data.number))
{

getline(infile, data.list[i].Title);
infile >> data.list[i].Title;
infile >> data.list[i].PubYear;
infile >> data.list[i].ISBN;


i++;



}


}

-------------

Please help!!! I am stumped. If I glue the names together it comes fine, but I need to show the spaces in the cout.

Reply With Quote
  #2  
Old May 22nd, 2003, 10:38 PM
rpgwh rpgwh is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2003
Posts: 2 rpgwh User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
heres the whole program

PHP Code:
#include <iostream.h>
#include <fstream.h>
#include "apstring.h"
#include "apvector.h"
#include <iomanip.h>

struct BookInfoType
{
    
apstring Title;
    
apstring Author;
    
apstring ISBN;
    
apstring PubName;
    
int PubYear;
    
    
};


struct Book
{
    
int number;
    
apvector<BookInfoType> list;
    
};

void getData(Book &data);
void printData(Book &data);

main()
{

    
Book data;
    

    
getData(data);
    
printData(data);

    return 
0;
}


void getData(Book &data)
{
    
ifstream infile("data.txt"ios::in);

    
infile >> data.number;

    
data.list.resize(data.number);


int i 0;
    
    while((!
infile.eof() && data.number))
    {
        
        
getline(infiledata.list[i].Title);
        
infile >> data.list[i].Title;
        
infile >> data.list[i].PubYear;
        
infile >> data.list[i].ISBN;
        
        
        
i++;
        
        

    }


}


void printData(Book &data)
{


    for(
int k 0data.numberk++)
    {

    
    
cout << data.list[k].Title << setw(10);
    
cout << data.list[k].PubYear << setw(10);
    
cout << data.list[k].ISBN << setw(10);
    
cout << endl;

    }

    
cout << endl;




-------------

HELP I am screwed. I have finals and I need to know how to do this. I have searched all over the internet without finding an example of this.

Last edited by rpgwh : May 22nd, 2003 at 10:48 PM.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > AP Computer Science Help - Structs

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap