Fixing Error C2664 in Visual 2008 C++

  • Thread starter Sumaya
  • Start date
In summary, the conversation is about a person working in visual 2008 c++ and encountering an error while using the get function in the program. The error is caused by trying to convert a parameter from a char array to a char. The solution is to use one of the overloads of the get function that takes two arguments.
  • #1
Sumaya
29
0

Homework Statement



I am working in visual 2008 c++ ... The is an errors on error C2664: 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::get(_Elem &)' : cannot convert parameter 1 from 'char [20]' to 'char &'


Homework Equations





The Attempt at a Solution



Code:
#include "stdafx.h"


// Assignment I files.cpp : Defines the entry point for the console application.
//


#include<iostream>
#include<fstream>
#include<string>
using namespace std;
struct person
{
	char name[20];
	int id;
};

void main()
{
//3.
char c[20];
int y;
ifstream infile("person.txt");
for(int i=0;i<5;i++)
{
infile>>c>>y;
cout<<c<<"  "<<y<<endl;
}
//4.
infile.seekg(8L,ios::beg);
	infile>>c>>y;
	cout<<c<<"  "<<y;
	while(infile.peek()!=EOF)
	{
		infile.get(c);
		cout<<c;
	}
	infile.close();

	

}
 
Physics news on Phys.org
  • #2
No overload of get takes a single argument of type char[]. To read multiple characters from the stream use one of the overloads that takes two args. Here is some documentation for istream::get - http://www.cplusplus.com/reference/iostream/istream/get/.
 

FAQ: Fixing Error C2664 in Visual 2008 C++

What is Error C2664 in Visual 2008 C++?

Error C2664 is a type of compiler error that occurs in Visual 2008 C++ when there is a mismatch in function parameters. This means that the arguments passed to a function do not match the expected parameters, either in type or number.

How do I fix Error C2664 in Visual 2008 C++?

To fix Error C2664, you should carefully check the function call and the function declaration to ensure that the parameters match. If necessary, you may need to modify one or both to correct the mismatch. Additionally, you should also check for any potential type conversions that may be causing the error.

Why does Error C2664 occur in Visual 2008 C++?

Error C2664 occurs in Visual 2008 C++ when there is a mismatch in function parameters. This can happen if the function call and declaration do not match, or if there is a mismatch in the types of the arguments being passed. It can also occur if there is a problem with type conversions.

Can I ignore Error C2664 in Visual 2008 C++?

No, you should not ignore Error C2664 in Visual 2008 C++. This error indicates a problem with your code and will prevent your program from compiling and running correctly. It is important to fix this error in order to ensure the proper functionality of your code.

Are there any tools to help identify and fix Error C2664 in Visual 2008 C++?

Yes, there are several tools that can help identify and fix Error C2664 in Visual 2008 C++. These include the compiler itself, which will provide information about the specific error and where it occurs in your code. Additionally, there are debugging tools and plugins available that can help pinpoint and resolve this error.

Similar threads

Replies
15
Views
2K
Replies
3
Views
969
Replies
8
Views
2K
Replies
2
Views
4K
Replies
23
Views
7K
Replies
2
Views
3K
Replies
1
Views
1K
Replies
5
Views
2K
Back
Top