Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: HUGE C++ Problem

  1. Dec 10, 2009 #1
    The code would be too long to paste here, so I've put it up on PasteBin.

    http://pastebin.com/m1190678c [Broken]

    My compiler has an issue with every single getline():

    This is just for the one on line 161.
    Code (Text):
    Error   4   161 error C2784: 'std::basic_istream<_Elem,_Traits> &std::getline(std::basic_istream<_Elem,_Traits> &,std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'std::basic_istream<_Elem,_Traits> &' from 'std::ifstream'   e:\users\ashwin\my stuff\school\post secondary\2009\kwantlen\school work\fall semester\cpsc 1103\assignments\assignment 5\cpsc1103_asgn05\cpsc1103_asgn05\cpsc1103_asgn05_combinedcode.cpp


    Error   5   161 error C2784: 'std::basic_istream<_Elem,_Traits> &std::getline(std::basic_istream<_Elem,_Traits> &,std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'std::basic_string<_Elem,_Traits,_Alloc> &' from 'int'   e:\users\ashwin\my stuff\school\post secondary\2009\kwantlen\school work\fall semester\cpsc 1103\assignments\assignment 5\cpsc1103_asgn05\cpsc1103_asgn05\cpsc1103_asgn05_combinedcode.cpp


    Error   6   161 error C2780: 'std::basic_istream<_Elem,_Traits> &std::getline(std::basic_istream<_Elem,_Traits> &,std::basic_string<_Elem,_Traits,_Alloc> &,const _Elem)' : expects 3 arguments - 2 provided    e:\users\ashwin\my stuff\school\post secondary\2009\kwantlen\school work\fall semester\cpsc 1103\assignments\assignment 5\cpsc1103_asgn05\cpsc1103_asgn05\cpsc1103_asgn05_combinedcode.cpp
     
    Also it appparently thinks I'm missing a ')' in the for loop on line 158, and a ';' before the '{' on 159.

    I have no clue what's going on. Can someone please help me?
     
    Last edited by a moderator: May 4, 2017
  2. jcsd
  3. Dec 10, 2009 #2

    mgb_phys

    User Avatar
    Science Advisor
    Homework Helper

  4. Dec 10, 2009 #3

    Borek

    User Avatar

    Staff: Mentor

    line ++9?
     
  5. Dec 10, 2009 #4

    mgb_phys

    User Avatar
    Science Advisor
    Homework Helper

    Better than some code comments i have read!
     
  6. Dec 10, 2009 #5

    Mark44

    Staff: Mentor

    Agreed, but there are a few comments that are not very useful, notably in the Inv function. It's obvious to the reader that the InvInfo function is being called, so a comment that says that isn't providing any extra information. (Line numbers omitted below.)
    Code (Text):

    case 1: cout << "Accessing Book Information Function..." << endl; InvInfo(bookinfo); break; //calls InvInfo()
    case 2: cout << "Accessing Search Function..." << endl; InvSearch(bookinfo); break; //calls InvSearch()
     
     
  7. Dec 10, 2009 #6
    Basically the way the text file is formatted is:
    Code (Text):

    ISBN
    Title
    Author
    Publisher
    Quantity
    Wholesale Price
    Retail Price
    Date Added

    ISBN
    Title
    Author
    Publisher
    Quantity
    Wholesale Price
    Retail Price
    Date Added
    So you read 8 lines, move 9 down, and repeat. I'll try to fix the getlines.

    So how would I format the getlines to pull a line from the file and feed it into the structure?
     
    Last edited: Dec 10, 2009
  8. Dec 10, 2009 #7
    Ok, so I tried to mess with the getlines, but now it's just being dumb.

    Here's a sample.

    It was this:

    invfile is the filestream, and the second argument is the structure address.
    Code (Text):
    getline(invfile, BookData.publisher)
    Then it apparently, needed three variables. So I did this:

    Code (Text):
    getline(invfile, BookData.publisher, '\n')
    Then it needed only two...what the hell?
     
  9. Dec 11, 2009 #8

    Mark44

    Staff: Mentor

    There are two getline functions, one with two params, and one with three.
     
  10. Dec 11, 2009 #9
    Yeah, I managed to get it figure it out. Now I need to fine-tune it. Thanks for your help everyone
     
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook