OK, so I’m trying to do a simple program that reads 2 input files (names & grades), then displays and prints them to an output file. So far I have this:
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
#include <sstream>
using namespace std;
void ReadNames();
void ReadGrades();
void ReadNames()
{
char names [15][5];
ifstream myfile("names.txt");
if(myfile.is_open())
{
while(!myfile.eof())
{
for (int i = 0; i < 11; i++)
{
myfile.get(names[i],15,'\0');
cout << names[i];
}
}
cout << endl;
}
else cout << "Error loadng file!" << endl;
}
void ReadGrades()
{
char grades [15][5];
ifstream myfile2("grades.txt");
if(myfile2.is_open())
{
while(!myfile2.eof())
{
for (int k = 0; k < 11; k++)
{
myfile2.get(grades[k],15,'\0');
cout << grades[k];
}
}
cout << endl;
}
else cout << "Error loadng file!" << endl;
}
int main()
{
char Name [10];
int grade [10][10];
ReadNames();
ReadGrades();
for (int i = 0;i < 5; i++)
{
cout << Name[i];
for ( int j = 0; j < 5; j++)
grade [i][j] << " ";
cout << endl;
}
cout << endl;
system("pause");
return 0;
}
When I try to compile Visual Studio is giving me two errors:
illegal, right operand has type ‘const char [1]’
operator has no effect; expected operator with side-effect
I know it’s something simple but I have no idea what the problem is. The error seems to stem from the grade [i][j] << " "; line. Any help would be appreciated.
The errors are telling you you need somehting like
grade [i][j]is achar," "is aconst char[1], and there is nooperator<<that operates on such a RHS and LHS combination.