Fixing Error C2664 in Visual 2008 C++

  • Thread starter Thread starter Sumaya
  • Start date Start date
AI Thread Summary
Error C2664 in Visual 2008 C++ arises when attempting to pass a 'char[20]' array to a function expecting a 'char&'. The code snippet provided demonstrates an attempt to read data from a file into a character array, which is causing the conversion error. To resolve this, users should utilize the appropriate overload of the `istream::get` function that accepts a character array as an argument. Additionally, the code needs adjustments to handle reading multiple characters correctly. Properly referencing the documentation for `istream::get` can aid in implementing the necessary changes.
Sumaya
Messages
29
Reaction score
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
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/.
 

Similar threads

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