472,980 Members | 1,762 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,980 software developers and data experts.

Getline Compile Error C2665

Schwack
I've just started learning C++ (got bored at work) and I'm using VC++ to compile some simple code but I get a compile error in test.cpp when using "getline". I've searched the internet and this forum but can't find an answer. I hope that someone can help :-)

test.h:
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. class ReadFile
  8. {
  9. public:
  10.     //Constructor
  11.     ReadFile(string file_path = "\0") : text_file (file_path.c_str())
  12.     {
  13.         count = 0;
  14.     };
  15.  
  16.     //Destructor
  17.     ~ReadFile()
  18.     {
  19.         text_file.close();
  20.     };
  21.  
  22.     long count;
  23.     string line();
  24.     bool end_of_file();
  25.  
  26. protected:
  27.     ifstream text_file;
  28.     string next_line;
  29.  
  30. };
test.cpp:
Expand|Select|Wrap|Line Numbers
  1. #include "test.h"
  2.  
  3. using namespace std;
  4.  
  5. string ReadFile::line()
  6.  
  7.     {
  8.         if (! text_file.eof())
  9.             {
  10.                 count += 1;
  11.             }
  12.  
  13.         ifstream::getline(text_file,next_line); // Get a line from the text file 
  14.         return next_line;
  15.     }
  16.  
  17. bool ReadFile::end_of_file()
  18.     {
  19.         return text_file.eof(); // Check if it's the end of the file
  20.     }
Build output:
------ Build started: Project: clr_project, Configuration: Debug Win32 ------
Compiling...
test.cpp
.\test.cpp(13) : error C2665: 'std::basic_istream<_Elem,_Traits>::getline' : none of the 2 overloads could convert all the argument types
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
C:\Program Files\Microsoft Visual Studio 9.0\VC\include\istream(593): could be 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::getline(_El em *,std::streamsize)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
while trying to match the argument list '(std::ifstream, std::string)'
Build log was saved at "file://c:\Documents and Settings\User\Desktop\clr_project\clr_project\Debu g\BuildLog.htm"
clr_project - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Jan 14 '08 #1
2 5239
Ok, I figured it out - really dumb typo in line 13, test.cpp

Expand|Select|Wrap|Line Numbers
  1. ifstream::getline(text_file,next_line);
All I had to do was remove "ifstream::" so tha the line read:

Expand|Select|Wrap|Line Numbers
  1. getline(text_file,next_line);
I can't believe how long it took for me to spot that!!!


I've just started learning C++ (got bored at work) and I'm using VC++ to compile some simple code but I get a compile error in test.cpp when using "getline". I've searched the internet and this forum but can't find an answer. I hope that someone can help :-)

test.h:
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. class ReadFile
  8. {
  9. public:
  10.     //Constructor
  11.     ReadFile(string file_path = "\0") : text_file (file_path.c_str())
  12.     {
  13.         count = 0;
  14.     };
  15.  
  16.     //Destructor
  17.     ~ReadFile()
  18.     {
  19.         text_file.close();
  20.     };
  21.  
  22.     long count;
  23.     string line();
  24.     bool end_of_file();
  25.  
  26. protected:
  27.     ifstream text_file;
  28.     string next_line;
  29.  
  30. };
test.cpp:
Expand|Select|Wrap|Line Numbers
  1. #include "test.h"
  2.  
  3. using namespace std;
  4.  
  5. string ReadFile::line()
  6.  
  7.     {
  8.         if (! text_file.eof())
  9.             {
  10.                 count += 1;
  11.             }
  12.  
  13.         ifstream::getline(text_file,next_line); // Get a line from the text file 
  14.         return next_line;
  15.     }
  16.  
  17. bool ReadFile::end_of_file()
  18.     {
  19.         return text_file.eof(); // Check if it's the end of the file
  20.     }
Build output:
------ Build started: Project: clr_project, Configuration: Debug Win32 ------
Compiling...
test.cpp
.\test.cpp(13) : error C2665: 'std::basic_istream<_Elem,_Traits>::getline' : none of the 2 overloads could convert all the argument types
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
C:\Program Files\Microsoft Visual Studio 9.0\VC\include\istream(593): could be 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::getline(_El em *,std::streamsize)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
while trying to match the argument list '(std::ifstream, std::string)'
Build log was saved at "file://c:\Documents and Settings\User\Desktop\clr_project\clr_project\Debu g\BuildLog.htm"
clr_project - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Jan 14 '08 #2
sicarie
4,677 Expert Mod 4TB
Thanks for posting your resolution, sorry we couldn't help.
Jan 14 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: xuatla | last post by:
Hi, I encountered the following compile error of c++ and hope to get your help. test2.cpp: In member function `CTest CTest::operator+=(CTest&)': test2.cpp:79: error: no match for 'operator='...
5
by: Brice Prunier | last post by:
Here under 4 schemas i'm working with ( it may be long: sorry...) The context is the following : Resident.xsd imports Person.xsd and includes Common.xsd ( anonimous schema: no TargetNamespace )...
10
by: Chris LaJoie | last post by:
Our company has been developing a program in C# for some time now, and we haven't had any problems with it, but just last night something cropped up that has me, and everyone else, stumped. I...
6
by: Thomas Connolly | last post by:
I have 2 pages referencing the same codebehind file in my project. Originally the pages referenced separate code behind files. Once I changed the reference to the same file, everything worked...
0
by: Jim Heavey | last post by:
Internal Compiler Error: stage 'BEGIN' Hello, I had an application which was working just fine and I decided to modify all database access within the application to utilizie a new Namespace that I...
2
by: Joseph Lu | last post by:
Hi, I have a multithread problem like the following lines, when I compile this code I caught a "error C2665", the error description is : none of the number1 overloads can convert parameter number2...
2
by: Angus | last post by:
Hello I have some classes defined in shapes.h and use them like this: const IShape* rectangle = new Rectangle(10.0, 20.0); // width, height cout << rectangle->calculateArea() << endl; ...
5
by: wong_powah | last post by:
#include <vector> #include <iostream> using std::cout; using std::vector; enum {DATASIZE = 20}; typedef unsigned char data_t;
7
by: Arjuna | last post by:
I have a class template (ExclusiveMap) which takes two type parameters C1 and C2 and declares two private members map<C1, C2> and map<C2, C1> (both STL maps). In test code I instantiate this class...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.