This is the code I have so far for this question...
Write a C++ program to read information of eight countries from an input file, called countries.txt. Write this information to an output file, called report.txt, in the format specified below.
Output format is
Statscan EDI
Code Code Country
======== ==== =======
12345 AB Cname
countries.txt is...
03461
Australia
AU
4023
Bahamas
BS
80021
Canada
CA
18712
Ethiopia
ET
20251
France
FR
34041
Lebanon
LB
38822
Mexico
MX
66721
United States
US
I have this much coded so far, but can't seem to understand these errors.
(5) : error C2365: 'std::getline' : redefinition; previous definition was 'function'
(5) : fatal error C1903: unable to recover from previous error(s); stopping compilation
(21) : error C2661: 'std::basic_istream<_Elem,_Traits>::getline' : no overloaded function takes 1 arguments
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
(21) : error C2059: syntax error : ')'
(22) : error C2664: 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::getline(_Elem *,std::streamsize)' : cannot convert parameter 1 from 'std::string' to 'char *'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
(23) : error C2664: 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::getline(_Elem *,std::streamsize)' : cannot convert parameter 1 from 'std::string' to 'char *'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
#include<iostream>
#include<fstream>
#include<string>
usingnamespace std;
// int std::getline; // error // solution delete
int main()
{
int scancode;
string country; // error should be char[] array
string abrev; // error should be char[] array
ifstream inData;
ofstream outData;
inData.open("countries.txt");
outData.open("report.txt");
while (!inData.eof())
{
inData.getline(scancode '\n'); // error missing comma and '\n' should be number
// solution inData >> scancode;
inData.getline(country, '\n'); // error require char[] array , '\n' should be number
// example inData.getline(country , sizeof(country))
inData.getline(abrev, '\n'); // error require char[] array , '\n' should be number
cout << scancode << endl;
}
inData.close();
outData << // error data is unfinish
// error outData is not close
return 0;
}