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

  • Context: Comp Sci 
  • Thread starter Thread starter Lancelot59
  • Start date Start date
  • Tags Tags
    C++
Click For Summary

Discussion Overview

The discussion revolves around troubleshooting errors in C++ code related to the use of the getline() function when reading data from a file. Participants explore issues with compiler errors and seek clarification on the correct usage of getline() in the context of file input.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • The original poster reports multiple compiler errors related to the getline() function, specifically mentioning issues with template argument deduction and missing syntax elements.
  • One participant points out that the original poster is not using getline() correctly and provides links to reference documentation.
  • Another participant humorously comments on the line numbers in the code, suggesting a light-hearted take on the situation.
  • There is a discussion about the usefulness of comments in the code, with some participants agreeing that certain comments do not add value.
  • The original poster describes the format of the text file being read, outlining the structure of the data and the expected number of lines to read.
  • Another participant suggests a need to format the getline() calls correctly to read data into a structure.
  • The original poster expresses frustration with the getline() function, noting confusion over the number of parameters required for different versions of the function.
  • A participant clarifies that there are two versions of getline(), one that takes two parameters and another that takes three.
  • The original poster later indicates they have resolved some issues and are now looking to refine their code further.

Areas of Agreement / Disagreement

Participants do not reach a consensus on the specific errors or the best approach to using getline(), as there are multiple interpretations and suggestions presented throughout the discussion.

Contextual Notes

There are unresolved issues regarding the specific syntax and usage of getline(), as well as the original poster's understanding of the function's parameters. The discussion reflects varying levels of familiarity with C++ file input operations.

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 ·
Replies
1
Views
2K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 14 ·
Replies
14
Views
3K
  • · Replies 7 ·
Replies
7
Views
8K
  • · Replies 2 ·
Replies
2
Views
7K