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

  • Thread starter Thread starter Lancelot59
  • Start date Start date
  • Tags Tags
    C++
AI Thread Summary
The discussion centers on resolving compilation errors related to the use of `getline()` in C++ code. The user encounters multiple errors indicating issues with template argument deduction and missing syntax elements in their code. They seek clarification on the correct usage of `getline()` and how to properly format it to read data into a structure from a text file. After some trial and error, they discover that `getline()` can accept either two or three parameters, depending on the context. The user expresses gratitude for the assistance received and indicates progress in resolving their issues.
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/
 
line ++9?
 
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?
 
There are two getline functions, one with two params, and one with three.
 
Yeah, I managed to get it figure it out. Now I need to fine-tune it. Thanks for your help everyone
 

Similar threads

Replies
1
Views
2K
Replies
3
Views
2K
Replies
1
Views
2K
Replies
1
Views
2K
Replies
2
Views
2K
Replies
14
Views
3K
Replies
7
Views
8K
Replies
2
Views
6K
Back
Top