Image

Imagejethro wrote in Imagecpp

I am taking my first programming class and this particular program is kicking my butt. I am having a problem with the cout/cin functions. I will put the code behind the lj cut thing.



#include [iostream] // I used the right symbols here, but the html messes them up
using namespace std;

int main()
{

//declare variables

string lastname = "";
int age = 0;
string product = "";
string prodcat = "";
int price = 0;
int quantity = 0;
const int discpercent = .10;
int newprice = 0;
int totalprice = 0;

//enter input items

cout << "Hello. May I have your last name please?:";
cin >> lastname;
cout << "Thank you. May I have your age?:";
cin >> age;
cout << "Which product will you be purchasing today?";
cin >> product;
return 0;
//end of main function
}

and the error message I am getting when compiling is

--------------------Configuration: prog2-jdb - Win32 Debug--------------------
Compiling...
prog2-jdb.cpp
C:\dl\prog2-jdb.cpp(31) : error C2679: binary '>>' : no operator defined which takes a right-hand operand of type 'class std::basic_string
[Error: Irreparable invalid markup ('<char,struct>') in entry. Owner must fix manually. Raw contents below.]

I am taking my first programming class and this particular program is kicking my butt. I am having a problem with the cout/cin functions. I will put the code behind the lj cut thing.

<lj-cut text="code here">
<b>
#include [iostream] // I used the right symbols here, but the html messes them up
using namespace std;

int main()
{

//declare variables

string lastname = "";
int age = 0;
string product = "";
string prodcat = "";
int price = 0;
int quantity = 0;
const int discpercent = .10;
int newprice = 0;
int totalprice = 0;

//enter input items

cout << "Hello. May I have your last name please?:";
cin >> lastname;
cout << "Thank you. May I have your age?:";
cin >> age;
cout << "Which product will you be purchasing today?";
cin >> product;
return 0;
//end of main function
}
</b>
and the error message I am getting when compiling is
<b>
--------------------Configuration: prog2-jdb - Win32 Debug--------------------
Compiling...
prog2-jdb.cpp
C:\dl\prog2-jdb.cpp(31) : 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 acceptable conversion)
C:\dl\prog2-jdb.cpp(35) : 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 acceptable conversion)
Error executing cl.exe.

prog2-jdb.obj - 2 error(s), 0 warning(s)
</B>
Can you not use the cin function with a string. I tried using the <b>getline</b> function [like this <b>getline(cin, lastname); </b>] but that didn't work either. Where am I going wrong?