Staredit Network > Forums > Technology & Computers > Topic: Another C++ Question
Another C++ Question
Sep 26 2007, 10:45 pm
By: l3lack-l3ahamut  

Sep 26 2007, 10:45 pm l3lack-l3ahamut Post #1

When attempting to compile my program it has 2 errors which both state: "C2679: binary '>>' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)"

Here is my program;

#include <iostream>
#include <iomanip>
#include <string.h>

using namespace std;

int main()
double gross,
hInsurance = 75.0,

string fname,

cout << "Enter employee's first and last name: " << flush;
cin >> fname >> lname; First error on this line

cout << "\nEnter employee's gross pay: " << flush;
cin >> gross;

federal = 0.15 * gross;
state = 0.035 * gross;
sSecurity = 0.0575 * gross;
medicare = 0.0275 * gross;
pension = 0.05 * gross;

net = gross - federal - state - sSecurity - medicare - pension - hInsurance;

cout << "\n\n" << fname << lname Second error on this line
<< "\nGross pay: " << gross
<< "\nFederal tax: " << federal
<< "\nState tax: " << state
<< "\nSocial Security tax: " << sSecurity
<< "\nMedicare / Medicade tax: " << medicare
<< "\nPension plan: " << pension
<< "\nNet pay: " << net << endl;

return 0;

I'd appreciate any help with this.


Sep 26 2007, 11:25 pm Matt Burch Post #2

On xCode (Mac) it shows no errors. I don't know what you are doing wrong. This looks like the Computer Science 20S assignment I had last year. Mine is canadian though.

The one I wrote was:
Name: Oops... hehehe.
Date: May 8th 2007
Assignment: 3-1
This program asks for the number of hours worked in a week, and your hourly wage.  To calculate your total wages, and your tax deductions, outputing your net income.

#include <iomanip.h>

int main()
    cout.setf(ios::fixed, ios::floatfield);

    float regular_Time, rate_Of_Pay, total_Wages, overtime, income_Tax, provincial_Tax, cpp, ei, net_Income, regular_Wage, overtime_Wage;
    cout<<"\n\n\tThis program will calculate your total wages, tax deductions, and your net income.  Input your hours works and your wage.\n\n\thours worked: ";
    cout<<"\tHourly wage:  ";
    total_Wages = (regular_Time * rate_Of_Pay );
    overtime = regular_Time - 40;
    regular_Wage = rate_Of_Pay * ( regular_Time - overtime );
    overtime_Wage = ( ( rate_Of_Pay * 1.5 ) * overtime );
    if ( regular_Time > 40 )
        total_Wages = regular_Wage + overtime_Wage;
    } else if ( regular_Time <= 40 )
        total_Wages = regular_Wage;
    }//end if
    income_Tax = ( total_Wages * 0.17 );
    provincial_Tax = ( total_Wages * 0.07 );
    cpp = ( total_Wages * 0.039 );
    ei = ( total_Wages * 0.0255 );
    net_Income = ( total_Wages - income_Tax - provincial_Tax - cpp - ei );
    cout<<setprecision(0)<<"\n\n"<<regular_Time<<setprecision(2)<<" hours at $"<<rate_Of_Pay<<"/hour\n\t";
    cout<<setprecision(0)<<regular_Time - overtime<<setprecision(2)<<" hours regular time"<<setw(17)<<regular_Wage<<"\n\t";
    cout<<setprecision(0)<<overtime<<" hours overtime"<<setprecision(2)<<setw(22)<<overtime_Wage<<"\n\t";
    cout<<"Total wages"<<setw(27)<<total_Wages<<"\n\n\t";
    cout<<"Income Tax"<<setw(28)<<income_Tax<<"\n\t";
    cout<<"Provincial Tax"<<setw(24)<<provincial_Tax<<"\n\t";
    cout<<"Net Income"<<setw(28)<<net_Income;
    return 0;
}//end int main

When I run the program, I got:
Enter employee's first and last name: John Doe

Enter employee's gross pay: 450.00

Gross pay: 450
Federal tax: 67.5
State tax: 15.75
Social Security tax: 25.875
Medicare / Medicade tax: 12.375
Pension plan: 22.5
Net pay: 231

Vhaeraun has exited with status 0.

Post has been edited 2 time(s), last time on Sep 26 2007, 11:26 pm by Matt Burch. Reason: Stupid "4"!! Grr..


Sep 26 2007, 11:33 pm l3lack-l3ahamut Post #3

maybe I'll just copy the source into a few project and see if it works then.


Sep 26 2007, 11:36 pm AntiEsponeo Post #4

Works fine for me too.


Sep 26 2007, 11:39 pm l3lack-l3ahamut Post #5

seriously? it gave the same errors again...


Sep 26 2007, 11:41 pm Matt Burch Post #6

Are you using a mac? On xCode? Because lots of programs I make on xCode on my Mac, don't work on windows at all.


Sep 26 2007, 11:43 pm l3lack-l3ahamut Post #7

No I'm using Visual C++ Express on windows. This is the first time its been like this.


well it worked after I changed the string.h to just <string> which didn't work the first time either so idk but it works now.

Post has been edited 1 time(s), last time on Sep 26 2007, 11:54 pm by Vhaeraun.


Sep 26 2007, 11:54 pm Matt Burch Post #8

Try doing:
cout << "Enter employee's first and last name: " << flush;
getline(cin, fname, ' ');
getline(cin, lname);

You'll need to change that other line to:
cout << "\n\n" << fname << " " << lname
to have it have the name seperated when it displays it.
I'll think a bit more, for the second part.


Sep 27 2007, 12:00 am l3lack-l3ahamut Post #9

well I got it to work then I started adding more to it and now it wont even link:
"1>LINK : fatal error LNK1168: cannot open C:\Documents and Settings\Mike\My Documents\Visual Studio 2005\Projects\prog ex 6\Debug\prog ex 6.exe for writing"


Sep 27 2007, 1:45 am ShadowFlare Post #10

That means that your program is probably still running. Check the task manager process list for your program, if needed. If it isn't there, then just try building it again. Occasionally it gives that error on your first try building projects even if your program isn't running.


Sep 27 2007, 2:20 am Falkoner Post #11

Man! You guys make your programs really hard to read! Space things out!


Sep 27 2007, 3:39 am Twitch Post #12

I tried this aswell it gave me the same errors I use dev C++ so I don't know how a mac user gets it to work.Try renaming those lines and see if it fixes it I have done that before and it fixed :l.


Sep 27 2007, 2:00 pm l3lack-l3ahamut Post #13

Quote from ShadowFlare
That means that your program is probably still running. Check the task manager process list for your program, if needed. If it isn't there, then just try building it again. Occasionally it gives that error on your first try building projects even if your program isn't running.

Yeah I tried that but it wasn't even running and I've tried to build it like 20 times.


  Back to forum
Please log in to reply to this topic or to report it.
Members in this topic: None.
[03:29 pm]
lil-Inferno -- penis XD
[05:40 am]
da real donwano -- Society is not ready for the AI power we're being given. I'll die on that hill.
[06:04 pm]
Zoan -- Like it's immoral either way imo to manipulate people falsely; just it's gonna be a lot more common to do it with AI
[06:02 pm]
Zoan -- Like it's kinda just their art form. But with AI, any random dude who just wants to manipulate people for selfish reasons can use it instantly
[06:01 pm]
Zoan -- I think everyone believes that people who can actually copy someone else's voice to such a degree that it's indistinguishable have to train for years to do that, and so they wouldn't necessarily use it for evil purposes
[05:59 pm]
Ultraviolet -- Might get into a "they took our jobs!" type of situation :lol:
[05:58 pm]
Ultraviolet -- I always thought it was kind of messed up to impersonate someone without their permission, but I guess that's artistic license for you. When you get into the realm of using AI to do it.. it seems even worse to me, but I'm not sure why
[2023-12-05. : 3:07 pm]
Oh_Man -- guys what are your thoughts on AI voice cloning vs someone doing impressions. why is one moral and the other immoral? or do you think both are fair game
[2023-12-05. : 1:48 pm]
Ultraviolet -- Also, are you referring to my switch to Ultraviolet from NerdyTerdy? :P I remember folks didn't really approve of the change, still get called Nerdy around here heh
[2023-12-05. : 1:47 pm]
Ultraviolet -- NudeRaider
NudeRaider shouted: Ultraviolet Whenever I read NR I feel talked to. :P Also things with your user name. ;)
ah shoot, yeah I guess you're the main NR at this point, but I always call you Nude. For me, NR is nuclearrabbit lol
Please log in to shout.

Members Online: lil-Inferno, NudeRaider, jemes_kowalski_56