weird errors
Hi, I'm new. I've been playing with C++ for a while now. I'm currently a CS major, and taking Intro to Programming for the second time. I've been working on this program (an assignment for class) that takes three employees names, and their respective genders and ages, and puts them in a neat little file. Here's the sourcecode:
#include#include #include using namespace std; void main() { string name = ""; char sex; int age; int n = 1; //for the while loop ofstream fout("emps.txt"); fout<
[Error: Irreparable invalid markup ('<left<<setw(15)<<"name"<<right<<setw(5)<<"age">') in entry. Owner must fix manually. Raw contents below.]
Hi, I'm new. I've been playing with C++ for a while now. I'm currently a CS major, and taking Intro to Programming for the second time. I've been working on this program (an assignment for class) that takes three employees names, and their respective genders and ages, and puts them in a neat little file. Here's the sourcecode: <lj-cut>
<pre>#include<iostream>
#include<fstream>
#include<iomanip>
using namespace std;
void main()
{
string name = "";
char sex;
int age;
int n = 1; //for the while loop
ofstream fout("emps.txt");
fout<<left<<setw(15)<<"Name"<<right<<setw(5)<<"Age"
<<setw(5)<<"Sex";
while(n<4)
{
cout<<"Enter employee number "<<n<<"'s name: ";
getline(cin,name);
cout<<"Enter employee number "<<n<<"'s age: ";
cin>>age;
cout<<"Enter employee number "<<n<<"'s sex: ";
cin>>sex;
fout<<left<<setw(15)<<name<<right<<setw(5)<<age
<<setw(5)<<sex;
n=n+1;
}
}</pre>
I get the following output when trying to compile:
<tt>--------------------Configuration: p144_num10 - Win32 Debug--------------------
Compiling...
emp_table.cpp
E:\CSC108_TAKE2\p144_num10\emp_table.cpp(32) : error C2065: 'getline' : undeclared identifier
E:\CSC108_TAKE2\p144_num10\emp_table.cpp(39) : error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (or there is no acceptab
le conversion)
Error executing cl.exe.
emp_table.obj - 2 error(s), 0 warning(s)</tt></lj-cut>
I've no idea what I've done wrong.
<pre>#include<iostream>
#include<fstream>
#include<iomanip>
using namespace std;
void main()
{
string name = "";
char sex;
int age;
int n = 1; //for the while loop
ofstream fout("emps.txt");
fout<<left<<setw(15)<<"Name"<<right<<setw(5)<<"Age"
<<setw(5)<<"Sex";
while(n<4)
{
cout<<"Enter employee number "<<n<<"'s name: ";
getline(cin,name);
cout<<"Enter employee number "<<n<<"'s age: ";
cin>>age;
cout<<"Enter employee number "<<n<<"'s sex: ";
cin>>sex;
fout<<left<<setw(15)<<name<<right<<setw(5)<<age
<<setw(5)<<sex;
n=n+1;
}
}</pre>
I get the following output when trying to compile:
<tt>--------------------Configuration: p144_num10 - Win32 Debug--------------------
Compiling...
emp_table.cpp
E:\CSC108_TAKE2\p144_num10\emp_table.cpp(32) : error C2065: 'getline' : undeclared identifier
E:\CSC108_TAKE2\p144_num10\emp_table.cpp(39) : error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (or there is no acceptab
le conversion)
Error executing cl.exe.
emp_table.obj - 2 error(s), 0 warning(s)</tt></lj-cut>
I've no idea what I've done wrong.
