Isabella Chan Isabella Chan - 1 month ago 9
C++ Question

invalid conversion from 'int' to 'char *'

I am suppose to write a program that will read from a text file and store what is inside the text file using structures and regroup and print out the information in the text file. But I have encountered problems with

. I have try to write
like this


but it doesn't work. I have also include
but I still encounter errors like

error C2664: 'std::basic_istream<_Elem,_Traits>
&std::basic_istream<_Elem,_Traits>::getline(_Elem *,std::streamsize)'
: cannot convert parameter 1 from 'int' to 'char *'


error C2664: 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::getline(_Elem
*,std::streamsize,_Elem)' : cannot convert parameter 1 from 'char [10][80]' to 'char *'

The text file that I am suppose to print out is the below text

Isabella Chan
Republic of Singapore
Libra 23 - 10 -
I wish to be good in c++
I wish that
christina grimmie will win the voice
I wish that ......

Sorry for the noob question and thanks in advance!

#include <iomanip>
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <cctype>
#include <fstream>
#include <string>

using namespace std;

const int MAX = 80;
const int MAXNO = 10;
enum Zodiac
Aquarius, Pisces, Aries, Taurus,
Gemini, Cancer, Leo, Virgo,
Libra, Scorpio, Sagittarius, Capricorn
struct Date
Zodiac sign;
int day;
int month;
int year;
struct Student
char name [MAX];
char nationality [MAX];
Date birthDate;
int no; // no of other messages
char wishMessage [MAXNO][MAX];
// Feel free to add in more features

void myInfo (fstream&, char [], Student&);
// The above function reads information from the text file
// and store the information in a structure reference parameter

void printOut(Student);

int main()
fstream infile;
char fName[MAX];
Student info;
cout << "Enter your info file name: "
cin >> fName;
cout << endl;

myInfo(infile, fName, info);


void myInfo (fstream& infile, char fName[], Student& info)
{, ios::in);

cout << "Error file not found!" << endl;
infile.getline(, MAX);
infile << info.birthDate.sign
<< info.birthDate.month
<< info.birthDate.year;
infile.getline(, MAX);
infile.getline(info.wishMessage, MAXNO, MAX);

cout << "Successfully readed!" << endl;


void printOut(Student info)
cout << "My name is " << << endl;
cout << "My nationality is " << info.nationality << endl;
cout << "My date of birth is " <<
<< " " << info.birthDate.month << " "
<< info.birthDate.year << endl;
cout << "I am " << info.birthDate.sign << endl;
cout << "\n I have " << << " wishes:" << endl;



It seems that you are trying to read into non-strings with getline, whereas it is reading into strings as per documentation.

Extracts characters from the stream as unformatted input and stores them into s as a c-string, until either the extracted character is the delimiting character, or n characters have been written to s (including the terminating null character).

Here are two offending lines:

infile.getline(, MAX);


infile.getline(info.wishMessage, MAXNO, MAX);

The former is reading into int, the latter is into a string array.

You will need to first read the strings in, and then make the corresponding conversion operations as desired.