iostream.h functions not working!

This is a discussion on iostream.h functions not working! within the C++ Programming forums, part of the General Programming Boards category; I can't get any iostream functions to work, when I run the program there is no output except for stdlib.h ...

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    49

    Angry iostream.h functions not working!

    I can't get any iostream functions to work, when I run the program there is no output except for stdlib.h functions.

    My source code is posted the the tread : "Can't figure out this darn linker!"
    DJGPP-Complier
    Windows 98-(Shouldn't need to explain)

    I like plants.

  2. #2
    Registered User zdude's Avatar
    Join Date
    Sep 2002
    Posts
    32
    Can't find that thread.

    You might wanna try #include <iostream> if its not there already.

    Also make sure your >> are facing the right direction.

    std::cout << "Hi\n";
    std::cin >> x
    Those who live by the sword get shot by those who don't.

    I can C.

    Compiler: gcc

  3. #3
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    Thread is here.

    Use the standard version of Iostreams (as zdude mentioned), and replace / with \ in control characters (\n, \t, not /n, /t).
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  4. #4
    Registered User
    Join Date
    Sep 2002
    Posts
    49

    Still will not work!!!

    I changed all the slashes and tried the standard versions of cout<< and cin>>, but it still will not work.

    I'm using Dev-C++ version 4, if it's the complier, please let me know.
    DJGPP-Complier
    Windows 98-(Shouldn't need to explain)

    I like plants.

  5. #5
    Cat
    Cat is offline
    Registered User
    Join Date
    May 2003
    Posts
    1,571
    Post your most recent code.

  6. #6
    Deleted Account
    Join Date
    Mar 2003
    Posts
    62
    >>I'm using Dev-C++ version 4, if it's the complier, please let me know.

    Nope I use dev-c++ 4, the same thing happened to me with with a diferent header file. I added like 500 header files and it didn't work afterward so I reinstalled it(hint hint). And it works just fine now.

  7. #7
    Registered User
    Join Date
    Sep 2002
    Posts
    49
    I'll try that zornthrohacker, but here is the code

    Code:
    #include <iostream.h>
    #include <stdlib.h>
    #include <DineOut.h>
    
    int main()
    {
     int DineOut;
     int YearBorn;
     int FinalNumber;
     int HaveYouHadBirth;
    
     std::cout<<"DINING OUT MATHEMATICS.\n\n";
     system("PAUSE");
     std::cout<<"\n";
     cout<<"\t"<<"Here is some really neat math!\n";
     cout<<"\a\v";
     cout<<"First, enter the number of times that \n";
     cout<<"you would like to dine out a week.\n";
     cout<<"(This number must be >1 but <10.)";
     cout<<"\n\n\t";
     cin>>DineOut;
     cout<<"\n\n";
     cout<<"Now, we will multiply this number by 2.\n";
     cout<<"(Just to be bold!)";
     cout<<"\n\n\t";
     cout<<DineOut<<" x 2 = "<<Twice(DineOut)<<"\n\n";
     system("PAUSE");
     cout<<"\n\n";
     cout<<"Now, we will add 5 for Sunday.";
     cout<<"\n\n\t";
     cout<<DineOut<<" + 2 = "<<AddFive(DineOut)<<"\n\n";
     system("PAUSE");
     cout<<"\n\n";
     cout<<"Now Multiply it by 50.";
     cout<<"\n\n\t";
     cout<<DineOut<<" x 50 = "<<FiftyTimes(DineOut)<<"\n\n";
     system("PAUSE");
     cout<<"\n\n";
     cout<<"Now, if you've had your birthday, please press 1. ";
     cout<<"\n"<<"If you haven't, please press two.";
     cout<<"\n\t";
     cin>>HaveYouHadBirth;
     if (HaveYouHadBirth==1)
     {
     cout<<"\n\n";
     cout<<"Since you've had your birthday, we'll add 1753.";
     cout<<"\n\n\t"<<DineOut<<" + 1753 = "<<HadBirth(DineOut);
     cout<<"\n\n";
     system("PAUSE");
     }
     else if (HaveYouHadBirth==2)
     {
     cout<<"\n\n";
     cout<<"Since you haven't had your birthday, we'll add 1752.";
     cout<<"\n\n\t"<<DineOut<<" + 1752 = "<<NotHadBirth(DineOut);
     cout<<"\n\n";
     system("PAUSE");
     }
     else
     {
     cout<<"You have not entered a valid number.\a\n\a\n";
     system("PAUSE");
     cout<<"This program will therefore not work correctly.";
     }
     cout<<"\n\n";
     cout<<"Now, enter the year you were born.";
     cout<<"\n\n\t";
     cin>>YearBorn;
     cout<<"\n\n";
     cout<<"Now, we will subtract the year you were born.";
     FinalNumber=DineOut - YearBorn;
     cout<<"\n\n\t"<<DineOut<<" - "<<YearBorn<<" = "<<FinalNumber;
     cout<<"\n\n";
     system("PAUSE");
     cout<<"\n\n";
     cout<<"Finally, you should be left with a three digit number.";
     cout<<"\n\t"<<FinalNumber;
     cout<<"The first digit is the number of times you would like to\n";
     cout<<"dine out a week.\n";
     cout<<"The last two numbers are:\n"<<"duh duh duh duuuuuuuuuhhhhhhh!!!\n";
     cout<<"YOUR AGE!!! HAHAHA!!!";
     system("PAUSE");
     return 0;
    
    
    }
    Here is DineOut.h:

    Code:
    class DineOut
    {
     public:
     double FiftyTimes(double x);
     double Twice(double x);
     double AddFive(double x);
     double HadBirth(double x);
     double NotHadBirth(double x);
    
     protected:
     double x;
    };
    
    double FiftyTimes(double x)
    {
     return x*50;
    }
    
    double Twice(double x)
    {
     return x*2;
    }
    
    double AddFive(double x)
    {
     return x+5;
    }
    
    double HadBirth(double x)
    {
     return x+1753;
    }
    
    double NotHadBirth(double x)
    {
     return x+1752;
    }
    DJGPP-Complier
    Windows 98-(Shouldn't need to explain)

    I like plants.

  8. #8
    Registered User
    Join Date
    Sep 2002
    Posts
    49
    reinstalling did not work
    DJGPP-Complier
    Windows 98-(Shouldn't need to explain)

    I like plants.

  9. #9
    Cat
    Cat is offline
    Registered User
    Join Date
    May 2003
    Posts
    1,571
    Code:
    #include <iostream>
    #include <cstdlib>
    #include "DineOut.h"
    <iostream> and <cstdlib> are the correct C++ way to include those features. Further, your own headers should be in ""s so the compiler will search the source directory for the header.

    Further, if you use <iostream>, you either need to have the line "using namespace std;", or you need std:: before *every* instance of cout and cin, not just a couple of them.

  10. #10
    Registered User
    Join Date
    Sep 2002
    Posts
    49
    changed to:

    Code:
     
    #include <iostream>
    #include <cstdlib>
    #include "DineOut.h"
    
    int main()
    {
     using namespace std;
    ...

    It still will not work.
    DJGPP-Complier
    Windows 98-(Shouldn't need to explain)

    I like plants.

  11. #11
    Cat
    Cat is offline
    Registered User
    Join Date
    May 2003
    Posts
    1,571
    Well, try out this:

    Code:
    #include <iostream>
    #include <cstdlib>
    
    int main(){
        using namespace std;
        cout << "Hello World" << endl;
        system("pause");
    }
    Does THAT work?

    One thing to note; cout can take as long as it wants to actually write to the screen. endl explicitly forces it to write to the screen (it flushes the output). So the above code will ALWAYS have the following output:

    Hello World
    Press any key to continue.

    But this code:

    Code:
    #include <iostream>
    #include <cstdlib>
    
    int main(){
        using namespace std;
        cout << "Hello World" << "\n";
        system("pause");
    }
    MIGHT have that output, but might also have this output:

    Press any key to continueHello World
    Last edited by Cat; 07-03-2003 at 04:13 PM.

  12. #12
    Registered User
    Join Date
    Sep 2002
    Posts
    49
    I even tried that, it must be something to do with the complier, or maybe iostream.h got messed up.
    DJGPP-Complier
    Windows 98-(Shouldn't need to explain)

    I like plants.

  13. #13
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    Is it actually compiling and not printing, or is there some compiler error?
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  14. #14
    Registered User
    Join Date
    Sep 2002
    Posts
    49
    It's actually compiling and not printing, it used to have a linker problem, but it's not showing one anymore.

    Is there anyone who can try the program and see if it works for them?
    DJGPP-Complier
    Windows 98-(Shouldn't need to explain)

    I like plants.

  15. #15
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    If you don't have any std::endl's, put a std::cout.flush() in right before system("pause")... See if that does anything.
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 11-17-2008, 01:00 PM
  2. Static functions.... why?
    By patricio2626 in forum C++ Programming
    Replies: 4
    Last Post: 04-02-2007, 09:06 PM
  3. Static member functions more efficient?
    By drrngrvy in forum C++ Programming
    Replies: 6
    Last Post: 06-16-2006, 08:07 AM
  4. Functions and Classes - What did I do wrong?
    By redmage in forum C++ Programming
    Replies: 5
    Last Post: 04-11-2005, 12:50 PM
  5. Functions are not working
    By founder247184 in forum C++ Programming
    Replies: 0
    Last Post: 11-29-2002, 04:00 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21