hi everyon i'm new and i need some help. I've been taking a class in C++ and i downloaded the C++ 2005 express edition to my laptop to work on it at home, and the header file iomanip.h doesn't work. I bet this is probally an easy fix but help would be great

Try just using <iomanip>. I'm guessing that you have VC6.0 or something at school, which uses old (deprecated) headers. The standard C++ headers don't have the .h extension. Unfortunately, lots of classes still use old compilers (like VC6 which even predates the C++ standard) and make it very annoying to move back and forth from class and home. If this is the case, you might also ask your instructor to consider upgrading, but do tread lightly there.

>now it doesn't know what cout or cin is
That's because all objects in the standard template library are encased inside the std:: namespace to avoid abiguities.

You have 2 options: prefix all objects with std::, like this:

std::cout << "hello world" << std::endl;

The other option is to place all the objects into global namespace:

#include <iostream>
using namespace std;

However, a word of caution: you're now placing all the objects into the global namespace, so there's a distinct possibility that you could end up naming an object identical names to an object already existing in the STL. One way around this is to manually place objects into the global namespace:

#include <iostream>
using std::cout;
using std::cin;
using std::endl;

This is my preferred method for using objects in the STL.

i did this:

#include <iostream>
using std::cout;
using std::cin;
using std::endl;

and got 28 errors
also i'm using a 'char' varible and i'm creating different functions. But the functions are simple adding, subtracting, multiplying and dividing.

Try just using <iomanip>. I'm guessing that you have VC6.0 or something at school, which uses old (deprecated) headers.

It uses the new headers, too.

It uses the new headers, too.

Which is exactly why the instructors use it: because they can. :rolleyes:

Which is exactly why the instructors use it: because they can. :rolleyes:

What's wrong with VC6 then?

What's wrong with VC6 then?

Hmm, well if the instructors used the latest version it wouldn't permit (or at least give lots of warnings, I haven't actually installed 2005 edition yet) the use of these old headers.

Meh, that statement was completely meaningless since VS 2005 won't even compile modern headers without giving warnings. Maybe I'll just go and hide...

Hmm, well if the instructors used the latest version it wouldn't permit (or at least give lots of warnings, I haven't actually installed 2005 edition yet) the use of these old headers.

VS2005 does give a warning, IIRC. ;)

Meh, that statement was completely meaningless since VS 2005 won't even compile modern headers without giving warnings. Maybe I'll just go and hide...

Won't compile modern headers? How so? (not that I've used it much for anything C++ related...)

>Won't compile modern headers? How so? (not that I've used it much for anything C++ related...)
Somehow Microsoft decided that they could write a better (read: unportable) version of the Standard Template Library, so now I believe you need a special #pragma to disable warnings that complain about "deprecated headers".

And that's using the modern headers.

[edit]
Actually (after some researching) it was a #define, not a #pragma.

this is the code, we were working on making new functions, and i added the switch statments

#include <iostream>
using std::cout;
using std::cin;
using std::endl;
#include <stdio.h>
#include <math.h>

//making new functions

int a,b;
char action;
int multiply(int, int);
int divide (int, int);
int add (int, int);
int sub (int, int);

int main() 
{
    cout << "type a number"; 
    cin >> a;
    cout << "type another number";
    cin >> b;

   cout << "what would you like to do? (+,-,* or /)" << std::endl;
    cout >> action;
    
    switch (action)
    {
    case '+':
    case '=':// = is + not shifted 
        cout << add (a,b);
        break;
    case '-':
        cout << sub (a,b);
        break;
    case '/':
        cout << divide (a,b);
        break;
    case '8':
    case '*':    
        cout << multiply (a,b);
        break; 
    }//end of switch
    return 0;
}

int multiply (int tempa, int tempb)
{
    return (tempa*tempb);
}//end of mult

     int add (int tempa, int tempb)
     {
     return (tempa+tempb);
    }//end of add
         
         int sub (int tempa, tempb)
         {
           return (tempa-tempb);
         }// end of sub 
            int divide (int tempa, tempb)
            {
                return (tempa/tempb);
            }// end of divde

and this is the errors,
.\code.cpp(25) : error C2784: 'std::basic_istream<char,_Traits> &std::operator >>(std::basic_istream<char,_Traits> &,unsigned char &)' : could not deduce template argument for 'std::basic_istream<char,_Traits> &' from 'std::ostream'
C:\Program Files\Microsoft Visual Studio 8\VC\include\istream(1016) : see declaration of 'std::operator >>'
.\code.cpp(25) : error C2784: 'std::basic_istream<char,_Traits> &std::operator >>(std::basic_istream<char,_Traits> &,unsigned char &)' : could not deduce template argument for 'std::basic_istream<char,_Traits> &' from 'std::ostream'
C:\Program Files\Microsoft Visual Studio 8\VC\include\istream(1016) : see declaration of 'std::operator >>'
.\code.cpp(25) : error C2784: 'std::basic_istream<char,_Traits> &std::operator >>(std::basic_istream<char,_Traits> &,unsigned char &)' : could not deduce template argument for 'std::basic_istream<char,_Traits> &' from 'std::ostream'
C:\Program Files\Microsoft Visual Studio 8\VC\include\istream(1016) : see declaration of 'std::operator >>'
.\code.cpp(25) : error C2784: 'std::basic_istream<char,_Traits> &std::operator >>(std::basic_istream<char,_Traits> &,unsigned char &)' : could not deduce template argument for 'std::basic_istream<char,_Traits> &' from 'std::ostream'
C:\Program Files\Microsoft Visual Studio 8\VC\include\istream(1016) : see declaration of 'std::operator >>'
.\code.cpp(25) : error C2784: 'std::basic_istream<char,_Traits> &std::operator >>(std::basic_istream<char,_Traits> &,unsigned char *)' : could not deduce template argument for 'std::basic_istream<char,_Traits> &' from 'std::ostream'
C:\Program Files\Microsoft Visual Studio 8\VC\include\istream(1009) : see declaration of 'std::operator >>'
.\code.cpp(25) : error C2784: 'std::basic_istream<char,_Traits> &std::operator >>(std::basic_istream<char,_Traits> &,unsigned char *)' : could not deduce template argument for 'std::basic_istream<char,_Traits> &' from 'std::ostream'
C:\Program Files\Microsoft Visual Studio 8\VC\include\istream(1009) : see declaration of 'std::operator >>'
.\code.cpp(25) : error C2784: 'std::basic_istream<char,_Traits> &std::operator >>(std::basic_istream<char,_Traits> &,unsigned char *)' : could not deduce template argument for 'std::basic_istream<char,_Traits> &' from 'std::ostream'
C:\Program Files\Microsoft Visual Studio 8\VC\include\istream(1009) : see declaration of 'std::operator >>'
.\code.cpp(25) : error C2784: 'std::basic_istream<char,_Traits> &std::operator >>(std::basic_istream<char,_Traits> &,unsigned char *)' : could not deduce template argument for 'std::basic_istream<char,_Traits> &' from 'std::ostream'
C:\Program Files\Microsoft Visual Studio 8\VC\include\istream(1009) : see declaration of 'std::operator >>'
.\code.cpp(25) : error C2784: 'std::basic_istream<char,_Traits> &std::operator >>(std::basic_istream<char,_Traits> &,signed char &)' : could not deduce template argument for 'std::basic_istream<char,_Traits> &' from 'std::ostream'
C:\Program Files\Microsoft Visual Studio 8\VC\include\istream(1002) : see declaration of 'std::operator >>'
.\code.cpp(25) : error C2784: 'std::basic_istream<char,_Traits> &std::operator >>(std::basic_istream<char,_Traits> &,signed char &)' : could not deduce template argument for 'std::basic_istream<char,_Traits> &' from 'std::ostream'
C:\Program Files\Microsoft Visual Studio 8\VC\include\istream(1002) : see declaration of 'std::operator >>'
.\code.cpp(25) : error C2784: 'std::basic_istream<char,_Traits> &std::operator >>(std::basic_istream<char,_Traits> &,signed char &)' : could not deduce template argument for 'std::basic_istream<char,_Traits> &' from 'std::ostream'
C:\Program Files\Microsoft Visual Studio 8\VC\include\istream(1002) : see declaration of 'std::operator >>'
.\code.cpp(25) : error C2784: 'std::basic_istream<char,_Traits> &std::operator >>(std::basic_istream<char,_Traits> &,signed char &)' : could not deduce template argument for 'std::basic_istream<char,_Traits> &' from 'std::ostream'
C:\Program Files\Microsoft Visual Studio 8\VC\include\istream(1002) : see declaration of 'std::operator >>'
.\code.cpp(25) : error C2784: 'std::basic_istream<char,_Traits> &std::operator >>(std::basic_istream<char,_Traits> &,signed char *)' : could not deduce template argument for 'std::basic_istream<char,_Traits> &' from 'std::ostream'
C:\Program Files\Microsoft Visual Studio 8\VC\include\istream(995) : see declaration of 'std::operator >>'
.\code.cpp(25) : error C2784: 'std::basic_istream<char,_Traits> &std::operator >>(std::basic_istream<char,_Traits> &,signed char *)' : could not deduce template argument for 'std::basic_istream<char,_Traits> &' from 'std::ostream'
C:\Program Files\Microsoft Visual Studio 8\VC\include\istream(995) : see declaration of 'std::operator >>'
.\code.cpp(25) : error C2784: 'std::basic_istream<char,_Traits> &std::operator >>(std::basic_istream<char,_Traits> &,signed char *)' : could not deduce template argument for 'std::basic_istream<char,_Traits> &' from 'std::ostream'
C:\Program Files\Microsoft Visual Studio 8\VC\include\istream(995) : see declaration of 'std::operator >>'
.\code.cpp(25) : error C2784: 'std::basic_istream<char,_Traits> &std::operator >>(std::basic_istream<char,_Traits> &,signed char *)' : could not deduce template argument for 'std::basic_istream<char,_Traits> &' from 'std::ostream'
C:\Program Files\Microsoft Visual Studio 8\VC\include\istream(995) : see declaration of 'std::operator >>'
.\code.cpp(25) : error C2784: 'std::basic_istream<_Elem,_Traits> &std::operator >>(std::basic_istream<_Elem,_Traits> &,_Elem &)' : could not deduce template argument for 'std::basic_istream<_Elem,_Traits> &' from 'std::ostream'
C:\Program Files\Microsoft Visual Studio 8\VC\include\istream(971) : see declaration of 'std::operator >>'
.\code.cpp(25) : error C2784: 'std::basic_istream<_Elem,_Traits> &std::operator >>(std::basic_istream<_Elem,_Traits> &,_Elem &)' : could not deduce template argument for 'std::basic_istream<_Elem,_Traits> &' from 'std::ostream'
C:\Program Files\Microsoft Visual Studio 8\VC\include\istream(971) : see declaration of 'std::operator >>'
.\code.cpp(25) : error C2784: 'std::basic_istream<_Elem,_Traits> &std::operator >>(std::basic_istream<_Elem,_Traits> &,_Elem &)' : could not deduce template argument for 'std::basic_istream<_Elem,_Traits> &' from 'std::ostream'
C:\Program Files\Microsoft Visual Studio 8\VC\include\istream(971) : see declaration of 'std::operator >>'
.\code.cpp(25) : error C2784: 'std::basic_istream<_Elem,_Traits> &std::operator >>(std::basic_istream<_Elem,_Traits> &,_Elem &)' : could not deduce template argument for 'std::basic_istream<_Elem,_Traits> &' from 'std::ostream'
C:\Program Files\Microsoft Visual Studio 8\VC\include\istream(971) : see declaration of 'std::operator >>'
.\code.cpp(25) : error C2784: 'std::basic_istream<_Elem,_Traits> &std::operator >>(std::basic_istream<_Elem,_Traits> &,_Elem *)' : could not deduce template argument for 'std::basic_istream<_Elem,_Traits> &' from 'std::ostream'
C:\Program Files\Microsoft Visual Studio 8\VC\include\istream(930) : see declaration of 'std::operator >>'
.\code.cpp(25) : error C2784: 'std::basic_istream<_Elem,_Traits> &std::operator >>(std::basic_istream<_Elem,_Traits> &,_Elem *)' : could not deduce template argument for 'std::basic_istream<_Elem,_Traits> &' from 'std::ostream'
C:\Program Files\Microsoft Visual Studio 8\VC\include\istream(930) : see declaration of 'std::operator >>'
.\code.cpp(25) : error C2784: 'std::basic_istream<_Elem,_Traits> &std::operator >>(std::basic_istream<_Elem,_Traits> &,_Elem *)' : could not deduce template argument for 'std::basic_istream<_Elem,_Traits> &' from 'std::ostream'
C:\Program Files\Microsoft Visual Studio 8\VC\include\istream(930) : see declaration of 'std::operator >>'
.\code.cpp(25) : error C2784: 'std::basic_istream<_Elem,_Traits> &std::operator >>(std::basic_istream<_Elem,_Traits> &,_Elem *)' : could not deduce template argument for 'std::basic_istream<_Elem,_Traits> &' from 'std::ostream'
C:\Program Files\Microsoft Visual Studio 8\VC\include\istream(930) : see declaration of 'std::operator >>'
.\code.cpp(25) : error C2676: binary '>>' : 'std::ostream' does not define this operator or a conversion to a type acceptable to the predefined operator
.\code.cpp(57) : error C2061: syntax error : identifier 'tempb'
.\code.cpp(59) : error C2065: 'tempb' : undeclared identifier
.\code.cpp(61) : error C2061: syntax error : identifier 'tempb'

EDIT: o darn some of the error turn into smileys

OK, well there's only like 3 or 4 errors here.

int main() 
{
    cout << "type a number"; 
    cin >> a;
    cout << "type another number";
    cin >> b;
    
    cout << "what would you like to do? (+,-,* or /)" << std::endl;
    cout >> action;  // use cin, not cout

You forgot to put 'int' in front of tempb :

int sub (int tempa, tempb)
{

Same here:

int divide (int tempa, tempb)
{

That should get your code compiling.

And btw I still don't see why you declared '=' as the same operation as '+'. :?:

yah i just realized the tempb had not int, and i made + and + because they are on the same button in case somone forgot to shift when they put their answer in.

and thanks that fixxed it

yah i just realized the tempb had not int, and i made + and + because they are on the same button in case somone forgot to shift when they put their answer in.

Well, I don't know about you, but I certainly don't like the idea of a calculator that tries to correct my equations that I enter in.

This article has been dead for over six months. Start a new discussion instead.