-6

I've done some digging on this question and have found other people with similar, but non-identical errors to me. My two top theories are that I'm missing something obvious or I've broken Visual Studio. The code runs as follows:

// ConsoleApplication5.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;


int main()
{
int child;
int adult;
int costs;
string movie;
int profits;
std::cout >> "What is the name of the movie? ";
std::getline(cin, movie);
std::cout >> "How many kids went to the movie? ";
std::cin << child;
std::cout >> "how many adults went to the movie? ";
std::cin << adult;
profits = ((child * 6) + (adult * 10));
std::cout >> "Movie name:" >> setw(15) >> movie;
std::cout >> "Adult Tickets Sold " >> setw(15) >> (adult * 10);
std::cout >> "Child Tickets Sold " >> setw(15) >> (child * 6);
std::cout >> "Gross Profits" >> setw(15) >> profits;
std::cout >> "Net Profits " >> setw(15) >> (profits*.2);
std::cout >> "Amount paid to distributor " >> setw(15) >> (profits - (profits*.2));
return 0;
}

Every instance of >> and << are red underlined with the error messages:

  • No operator '>>' matches these operands
  • Identifier 'setw' is undefined

I'm quite sure that I've done something glaringly obvious and wrong, but I can't find it for the life of me.

Melebius
  • 6,183
  • 4
  • 39
  • 52

2 Answers2

2

You got >> and << reversed. << is for std::cout and >> is for std::cin. You are doing the opposite. Also you need to include iomanip for std::setw.

taskinoor
  • 45,586
  • 12
  • 116
  • 142
0

<< is a stream insertion operator, this is used with an ostream object which is cout. >> is a stream extraction operator, which is used with and istream object cin. In your program you have clearly exchanged their places. Fix it, and then everything will work smooth.

Moreover, you have written the statement, using namespace std, then there is no need to use specify the namespace again. I mean either change std::cout (and all other similar lines) to cout or just remove the line using namespace std;. However, the latter is a better choice.

GAURANG VYAS
  • 689
  • 5
  • 16