Fixing Error C2664 in Visual 2008 C++

  • Thread starter Thread starter Sumaya
  • Start date Start date
Click For Summary
SUMMARY

The forum discussion addresses the C2664 error encountered in Visual Studio 2008 C++ when attempting to use the `std::basic_istream::get` function with a `char[20]` array. The error arises because the `get` function does not accept a single argument of type `char[]`. Instead, users should utilize an overload of `get` that accepts two parameters to read multiple characters from the input stream. The discussion provides a code snippet demonstrating the correct usage of file input operations with `ifstream` and highlights the need for proper parameter types.

PREREQUISITES
  • Understanding of C++ programming concepts
  • Familiarity with the Standard Template Library (STL)
  • Knowledge of file input/output operations in C++
  • Experience with Visual Studio 2008 IDE
NEXT STEPS
  • Review the documentation for `std::basic_istream::get` on Cplusplus.com
  • Learn about C++ character arrays and their manipulation
  • Explore file handling techniques in C++ using `ifstream` and `ofstream`
  • Investigate common C++ compilation errors and their resolutions
USEFUL FOR

C++ developers, students learning file I/O operations, and anyone troubleshooting compilation errors in Visual Studio 2008.

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 3 ·
Replies
3
Views
1K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 23 ·
Replies
23
Views
9K
  • · Replies 15 ·
Replies
15
Views
3K
  • · Replies 14 ·
Replies
14
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
5K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 9 ·
Replies
9
Views
3K