Ошибка компилятора c2679

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 exce...

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's user avatar

tmlen

8,1744 gold badges31 silver badges83 bronze badges

asked Oct 27, 2009 at 14:49

asyncwait's user avatar

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

sbi's user avatar

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

Lightness Races in Orbit's user avatar

answered Mar 9, 2018 at 11:35

Guy Avraham's user avatar

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 Delbar's user avatar

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

Akshat Bhatt's user avatar

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 Joe

    Thanks 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 &param) const;
     FrontalTracing* CreateFrontal(TempStorage &tempStorage, const PatientTracingInitParam &param) const;
     ArchTracing* CreateLowerArch (TempStorage &tempStorage, const PatientTracingInitParam &param) const ;
     ArchTracing* CreateUpperArch (TempStorage &tempStorage, const PatientTracingInitParam &param) 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

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

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 &copy);
    CFGArray& operator= (CFGArray&); // This is line Line 22
    };

Config.cpp

  • CFGArray::CFGArray(){this->RemoveAll();}
    CFGArray::CFGArray(const CFGArray &copy){
    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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
//Program Name:Project 1_Program 1
//Programmer Name: Jasmine Brown 
//Description: test the inherintance of class Vehicle
//Date Created: 10/14/2015

#include <iostream>

using namespace std;

class Vehicle
{
public:
	void setAge(int a)
	{
		age = a;
	}
	void setPrice(float p)
	{
		price = p;
	}
	float getAge()
	{
		return age;
	}
	float getPrice()
	{
		return price;
	}

	Vehicle();
	~Vehicle();

protected:
	int age;
	float price;
};

Vehicle::Vehicle()
{
	age = 0;
	price = 0.0;
}

Vehicle::~Vehicle()
{
}

class Car : public Vehicle
{
	protected:

		bool RaceCarStatus;

	public:

		void setRaceCarStatus(bool r)
		{
			RaceCarStatus = r;
		}

		bool getRaceCarStatus()
		{
			return RaceCarStatus;
		}

		
		Car();
		~Car();

};

Car::Car()
{
	RaceCarStatus = false;
}

Car::~Car()
{
}

class Truck: public Vehicle
{
	protected:
		bool DieselTypeStatus;

	public:	
		void setDieselTypeStatus(bool d)
		{
			DieselTypeStatus = d;
		}

		bool getDieselTypeStatus()
		{
			return DieselTypeStatus;
		}

		Truck();
		~Truck();
};

Truck::Truck()
{
	DieselTypeStatus = false;
}

Truck::~Truck()
{
}

int main(void)
{

	Vehicle v1;
	
	cout << "Vehicle age?: ";
	cin >> v1.setAge;
	
	cout << "Vehicle price?: ";
	cin >> v1.setPrice;
	


	system("pause");
	return 0;
}

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
int main(void)
{

	Vehicle v1;
	int a1;
	
	cout << "What is the vehicles age?: ";
	cin >> v1.setAge(a1);
	


	system("pause");
	return 0;
}

Last edited on

Sorry I called the function wrong. So this is it:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
int main(void)
{

	Vehicle v1,v2;
	int a1;
	
	cout << "What is the vehicles age?: ";
	cin >> a1;
	v1.setAge(a1);
	


	system("pause");
	return 0;
}

That fixed the problem. Thanks @TheIdeasMan and @LB

Topic archived. No new replies allowed.

Понравилась статья? Поделить с друзьями:
  • Ошибка компилятора c2676
  • Ошибка компилятора c2664
  • Ошибка компилятора c2064
  • Ошибка компилятора c2039
  • Ошибка компас 2146762487