HUGE C++ Problem: Solve Errors on Pastebin.com

  • Context: Comp Sci 
  • Thread starter Thread starter Lancelot59
  • Start date Start date
  • Tags Tags
    C++
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
8 replies · 3K views
Lancelot59
Messages
640
Reaction score
1
The code would be too long to paste here, so I've put it up on PasteBin.

http://pastebin.com/m1190678c

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

This is just for the one on line 161.
Code:
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.cppError	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.cppError	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:
Physics news on Phys.org
That's not how you use getline,
see http://www.cplusplus.com/reference/iostream/istream/getline/
or http://www.cplusplus.com/reference/string/getline/
 
Borek said:
line ++9?
Better than some code comments i have read!
 
mgb_phys said:
Better than some code comments i have read!
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:
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()
 
Basically the way the text file is formatted is:
Code:
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:
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:
getline(invfile, BookData.publisher)

Then it apparently, needed three variables. So I did this:

Code:
getline(invfile, BookData.publisher, '\n')

Then it needed only two...what the hell?
 
Yeah, I managed to get it figure it out. Now I need to fine-tune it. Thanks for your help everyone