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\ming w32\3.4.2\ include" -I"C:\Dev-Cpp\include\c++\ 3.4.2\back ward" -I"C:\Dev-Cpp\include\c++\ 3.4.2\ming w32" -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
#include<iostream>
#include<fstream>
#include<cstdlib>
using namespace test;
int main()
{
string emp = "Employee";
string empnam = "Name";
ofstream outFile;
outFile.open("febsales.txt
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\ming
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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;
}
#include<iostream>
#include<fstream>
#include<cstdlib>
using namespace test;
int main()
{
string emp = "Employee";
string empnam = "Name";
ofstream outFile;
outFile.open("febsales.txt
outFile << emp;
outFile << endl;
outFile << empnam;
outFile.close();
system("pause");
return 0;
}
ASKER
#include<fstream>
#include<cstdlib>
using namespace std;
int main()
{
string emp = "Employee";
string empnam = "Name";
ofstream outFile;
outFile.open("febsales.txt
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