[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Error during writing

Posted on 2011-04-22
3
Medium Priority
?
265 Views
Last Modified: 2013-12-16
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
0
Comment
Question by:mustish1
  • 2
3 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 2000 total points
ID: 35451782
no matching function for call to `getline(std::istream&, std::ofstream&)'

You are calling getline() with two stream arguments. The second parameter to getline() should be a string to hold the data.
no matching function for call to `getline(std::ofstream&)'

getline() takes two parameters, not one.
no match for 'operator>>' in 'outFile >> emp'

You're trying to use the input operator on an output stream.
`empname' undeclared (first use this function)

You declared "empnam", with no "e", but you are trying to use "empname", with an "e".
0
 

Author Comment

by:mustish1
ID: 35452738
#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
0
 

Author Closing Comment

by:mustish1
ID: 35454006
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;
}
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question