473,395 Members | 1,613 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 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 5270
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.