Link to home
Start Free TrialLog in
Avatar of mustish1
mustish1

asked on

Error during writing

Hi guys: I try to write two string on separate lines in a text file but keep getting errors


#include<iostream>
#include<fstream>
#include<cstdlib>

using namespace test;

int main()
{
    string emp = "Employee";
    string empnam = "Name";
    ofstream outFile;
    outFile.open("febsales.txt", ios::app);
    getline(cin, outFile);
    outFile >> emp;
    getline(outFile);
    outFile >> empname;    
    outFile.close();
    system("pause");
    return 0;
}



Compiler: Default compiler
Executing  g++.exe...
g++.exe "C:\Documents and Settings\Kathy\My Documents\test.cpp" -o "C:\Documents and Settings\Kathy\My Documents\test.exe"    -I"C:\Dev-Cpp\lib\gcc\mingw32\3.4.2\include"  -I"C:\Dev-Cpp\include\c++\3.4.2\backward"  -I"C:\Dev-Cpp\include\c++\3.4.2\mingw32"  -I"C:\Dev-Cpp\include\c++\3.4.2"  -I"C:\Dev-Cpp\include"   -L"C:\Dev-Cpp\lib"
C:\Documents and Settings\Kathy\My Documents\test.cpp: In function `int main()':
C:\Documents and Settings\Kathy\My Documents\test.cpp:13: error: no matching function for call to `getline(std::istream&, std::ofstream&)'
C:\Documents and Settings\Kathy\My Documents\test.cpp:14: error: no match for 'operator>>' in 'outFile >> emp'
C:\Documents and Settings\Kathy\My Documents\test.cpp:15: error: no matching function for call to `getline(std::ofstream&)'
C:\Documents and Settings\Kathy\My Documents\test.cpp:16: error: `empname' undeclared (first use this function)
C:\Documents and Settings\Kathy\My Documents\test.cpp:16: error: (Each undeclared identifier is reported only once for each function it appears in.)

Execution terminated
ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mustish1
mustish1

ASKER

#include<iostream>
#include<fstream>
#include<cstdlib>

using namespace std;

int main()
{
    string emp = "Employee";
    string empnam = "Name";
    ofstream outFile;
    outFile.open("febsales.txt", ios::app);
    getline(outFile);
    outFile >> emp;
    getline(outFile);
    outFile >> empnam;    
    outFile.close();
    system("pause");
    return 0;
}


C:\Documents and Settings\Kathy\My Documents\test.cpp:14: error: no match for 'operator>>' in 'outFile >> emp'
C:\Documents and Settings\Kathy\My Documents\test.cpp:15: error: no matching function for call to `getline(std::ofstream&)'
C:\Documents and Settings\Kathy\My Documents\test.cpp:16: error: no match for 'operator>>' in 'outFile >> empnam'

Execution terminated
Thanks.

#include<iostream>
#include<fstream>
#include<cstdlib>

using namespace test;

int main()
{
    string emp = "Employee";
    string empnam = "Name";
    ofstream outFile;
    outFile.open("febsales.txt", ios::app);
    outFile << emp;
    outFile << endl;
    outFile << empnam;    
    outFile.close();
    system("pause");
    return 0;
}