Please don’t confuse with the title as it was already asked by someone but for a different context
The below code in Visual C++ Compiler (VS2008) does not get compiled, instead it throws this exception:
std::ifstream input (fileName);
while (input) {
string s;
input >> s;
std::cout << s << std::endl;
};
But this code compiles fine in cygwin g++. Any thoughts?
tmlen
8,1744 gold badges31 silver badges83 bronze badges
asked Oct 27, 2009 at 14:49
0
Have you included all of the following headers?
<fstream>
<istream>
<iostream>
<string>
My guess is you forgot <string>
.
On a side note: That should be std::cout
and std::endl
.
answered Oct 27, 2009 at 15:07
sbisbi
217k45 gold badges254 silver badges440 bronze badges
12
Adding to @sbi answer, in my case the difference was including <string>
instead of <string.h>
(under VS 2017).
See the following answer: similar case answer
answered Mar 9, 2018 at 11:35
Guy AvrahamGuy Avraham
3,3723 gold badges40 silver badges49 bronze badges
In addition to what others said. The following code was necessary in my application to compile succesfully.
std::cout << s.c_str() << std::endl;
Another work-around to this is go to project properties -> General -> Character Set and choose «Ues Multi-Byte Character Set» (You won’t need to use c_str() to output the string)
There’s disadvantages to using MBCS so if you plan to localize your software, I’d advize against this.
answered Oct 24, 2018 at 16:10
Nick DelbarNick Delbar
1012 silver badges9 bronze badges
include <string>
Try including string header file along with <iostream>
file.
It will work in some compilers even without the <string>
because settings for different compilers are different and it is the compiler that is responsible for reading the preprocessor files that start with ‘#’ symbol to generate a obj file.
answered Aug 30, 2018 at 16:04
2
- Remove From My Forums
-
Question
-
Hi Everyone,
I’m totally new to programming, but I’m trying to learn. I thought I would reach out to the experts out in the community. When I compile an old C++ project in Visual Studio 2010 I get a C2679 error. Like I said, I am total newbee.
I bolded and underlined the line that pulls up as the issue. Here’s a copy of the code:Error 40 error C2679: binary ‘=’ : no operator found which takes a right-hand operand of type ‘const auto_orth_case’ (or there is no acceptable conversion) c:documents and settingsbsmith.rmodesktopjoe32updated joe232x 1.0.0.5 release
20040217includeksfilereader.h 83 1 JoeThanks for the help!
// KsFileReader.h: interface for the KsFileReader class.
//
//////////////////////////////////////////////////////////////////////#if !defined(AFX_KSFILEREADER_H__68B53D77_778B_11D1_A97E_0040051E93CB__INCLUDED_)
#define AFX_KSFILEREADER_H__68B53D77_778B_11D1_A97E_0040051E93CB__INCLUDED_#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000#include «FileFormatException.h»
#include «CaseData.h»
#include «LateralTracing.h»
#include «FrontalTracing.h»
#include «ArchTracing.h»class KsFileReader {
struct TempStorage {
//
CString m_name;
____ m_sex;
Race m_race;
Race m_norm;//
float m_age;
float m_skeletalAge;
float m_height;COleDateTime m_birthday, m_xRayDate;
ArchInfo m_upperArchInfo, m_lowerArchInfo;bool m_bLipsOpen;
int m_lateralCount;
CPoint m_lateralBuffer[169];int m_frontalCount;
CPoint m_frontalBuffer[123];int m_lowerArchCount;
CPoint m_lowerArchBuffer[29];int m_upperArchCount;
CPoint m_upperArchBuffer[29];
};auto_orth_case m_pOrthCase;
public:
KsFileReader(CArchive &ar);
virtual ~KsFileReader() {}static bool ReadPatientName(CString& patientName, CArchive& ar);
void GetOrthCase(auto_orth_case &pCaseFolder) const;private:
// File Reading
void ProcessCardNo1(TempStorage &tempStorage, PCSTR pszBuf);
void ProcessCardNo2(TempStorage &tempStorage, PCSTR pszBuf);
void ProcessTeethInfoCard(TempStorage &tempStorage, PCSTR pszBuf);static bool IsDigits(char* pszBuf);
static int ReadCardNo(PCSTR pszBuf);
static bool ReadDate(PCSTR pszBuf, COleDateTime &time);
static int ParsePointsCard (PCSTR pszBuf, CPoint* pPoints);static void AppendPoints(CPoint* pBuffer, int &nCount,
const CPoint* pSrc, int nPoints, int nMax);// Build Case object
void ConstructCase(TempStorage &tempStorage);
LateralTracing* CreateLateral(TempStorage &tempStorage, const PatientTracingInitParam ¶m) const;
FrontalTracing* CreateFrontal(TempStorage &tempStorage, const PatientTracingInitParam ¶m) const;
ArchTracing* CreateLowerArch (TempStorage &tempStorage, const PatientTracingInitParam ¶m) const ;
ArchTracing* CreateUpperArch (TempStorage &tempStorage, const PatientTracingInitParam ¶m) const ;
};inline void KsFileReader::GetOrthCase(auto_orth_case &pOrthCase) const {
pOrthCase = m_pOrthCase;
}#endif // !defined(AFX_KSFILEREADER_H__68B53D77_778B_11D1_A97E_0040051E93CB__INCLUDED_)
-
Edited by
Thursday, December 9, 2010 3:02 PM
-
Edited by
Answers
-
Hi Everyone,
Jinzai sent me a comment, which I don’t see posted here that fixed the issue. Thanks everyone.
Bryan
…I think that you will have to cast that reference in any event. m_pOrthCase is an auto_orth_case and you have the const modifier to contend with….
Does this eliminate the error? I tried to recreate a trivial example to test this, but…I did not receive the error that you got and it was not necessary to cast, either. Neither did I receive any
warnings when I cast the variable that was being set. (I used integers so as to avoid having to create a dummy class in a seperate file.)inline void KsFileReader::GetOrthCase(auto_orth_case &pOrthCase) const {
pOrthCase = (auto_orth_case &)m_pOrthCase;The Microsoft Developer Network
————————————————————————
-
Marked as answer by
brjan999
Thursday, December 16, 2010 4:06 PM
-
Marked as answer by
Hey Spiceworks Users,
I couldn’t find a C/C++ Programming group when choosing a group for this question, so I apologize in advance.
I am having to go through someone’s sloppy code and convert a program that was made in Visual Studio 6 to be useable in Visual Studio 2010, and I’ve hit this wall that I can’t seem to get over.
Here is the error I’m getting…
-
c:\program files\microsoft visual studio 10.0\vc\include\utility(217): error C2679: binary ‘=’ : no operator found which takes a right-hand operand of type ‘const CFGArray’ (or there is no acceptable conversion)
1> c:\work\pb\library\vc++\config.h(22): could be ‘CFGArray &CFGArray::operator =(CFGArray &)’
1> while trying to match the argument list ‘(CFGArray, const CFGArray)’
1> c:\program files\microsoft visual studio 10.0\vc\include\utility(215) : while compiling class template member function ‘std::pair<_Ty1,_Ty2> &std::pair<_Ty1,_Ty2>::operator =(const std::pair<_Ty1,_Ty2> &)’
1> with
1> [
1> _Ty1=CString,
1> _Ty2=CFGArray
1> ]
1> c:\work\pb\library\vc++\config.cpp(39) : see reference to class template instantiation ‘std::pair<_Ty1,_Ty2>’ being compiled
1> with
1> [
1> _Ty1=CString,
1> _Ty2=CFGArray
1> ]
Here is, what I think, is the relevant code…
Config.h
-
class CFGArray : public CArray<cfgValue, cfgValue>{
public:
CFGArray();
CFGArray(const CFGArray ©);
CFGArray& operator= (CFGArray&); // This is line Line 22
};
Config.cpp
-
CFGArray::CFGArray(){this->RemoveAll();}
CFGArray::CFGArray(const CFGArray ©){
this->RemoveAll();
int i;
for(i = 0; i < copy.GetSize(); ++i)
this->Add(copy[i]);
}
CFGArray& CFGArray::operator= (CFGArray& rhs){
if (this != &rhs) {
int i;
this->RemoveAll();
for(i = 0; i < rhs.GetSize(); ++i)
this->Add(rhs[i]);
}
return *this;
}
Any idea how I can fix this?
- Forum
- Beginners
- Error C2679. Need help fixing it.
Error C2679. Need help fixing it.
Hi! I’m trying to write a simple code where I test the inheritance of a class and two derived classes. I am a beginner and my professor wants to keep it simple. So no pointers or overloading. I’m not sure how to fix this error.
Oh the complete error is :
binary’>>’ no operator found which takes a right hand operand of type ‘overloaded — function’ or there is no acceptable conversion.
I am getting the error on my couts. The main is just to test if the methods in my class works and the derived classes methods work.
I am running VS 2015 if that helps.
I’m not sure why its happening because I’ve written a similar program and it has compiled with no errors.
|
|
Help would be greatly appreciated.
Last edited on
Hi,
The setAge
function is supposed to take an argument, you aren’t providing it with one. Try creating another variable in main
, get input for it, then call the function with that variable.
Good Luck :+)
@TheIdeasMan I did something like this and the error still will not go away
|
|
Last edited on
Sorry I called the function wrong. So this is it:
|
|
That fixed the problem. Thanks @TheIdeasMan and @LB
Topic archived. No new replies allowed.