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

  • Comp Sci
  • Thread starter Lancelot59
  • Start date
  • Tags
    C++
In summary, the conversation discusses issues with using getline() in a code and how it is not being used correctly. The conversation also mentions some unhelpful comments in the code and the formatting of a text file that is being used. The individual also mentions trying to fix the getline() issue and ultimately finding a solution.
  • #1
Lancelot59
646
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
  • #2
That's not how you use getline,
see http://www.cplusplus.com/reference/iostream/istream/getline/
or http://www.cplusplus.com/reference/string/getline/
 
  • #3
line ++9?
 
  • #4
Borek said:
line ++9?
Better than some code comments i have read!
 
  • #5
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()
 
  • #6
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:
  • #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:
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?
 
  • #8
There are two getline functions, one with two params, and one with three.
 
  • #9
Yeah, I managed to get it figure it out. Now I need to fine-tune it. Thanks for your help everyone
 

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

1. What is the most common cause of errors in C++ code?

The most common cause of errors in C++ code is syntax errors, which occur when the code does not follow the proper syntax rules of the language. These errors can include missing semicolons, incorrect use of parentheses, or misspelled keywords.

2. How can I solve these errors on Pastebin.com?

To solve errors on Pastebin.com, you will need to carefully review your code and look for any syntax errors or other mistakes. You can also use an online compiler or debugging tool to help identify and fix errors.

3. What is the best way to avoid errors in C++ code?

The best way to avoid errors in C++ code is to write clean and organized code, use proper indentation, and test your code frequently. It is also important to have a good understanding of the language and its rules.

4. Can I use a compiler to automatically fix errors on Pastebin.com?

No, compilers cannot automatically fix errors on Pastebin.com. They can only identify errors and provide suggestions for how to fix them. It is up to the programmer to make the necessary changes to the code.

5. What should I do if I am still unable to solve the errors on Pastebin.com?

If you are still unable to solve the errors on Pastebin.com, you can seek help from online forums or programming communities. You can also consult with a more experienced programmer or seek professional assistance.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Programming and Computer Science
Replies
5
Views
4K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
Back
Top