cin and cout

This is a discussion on cin and cout within the C++ Programming forums, part of the General Programming Boards category; I'm really new to C++ but i ahve a problem with cin and cout. in a simple program like eg. ...

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    24

    cin and cout

    I'm really new to C++ but i ahve a problem with cin and cout.

    in a simple program like eg.

    Code:
    #include <iostream.h>
    int main()
    {
     int x;
     cin>>x;
     cout<<"Your number was "<<x;
     return 0;
    }
    I have used cin and cout thinking it would print the text in some sort of console window but instead it prints it in a text file called stdout. The input only works if I create another text file in the same folder called stdin and type the input in there and save before running the program. Is this what it should do. If so then what other functions could I used to make it print in a console window?
    I am using Macintosh Programmers' Workshop on the Mac.

    Thanks
    #include <iostream.h>
    int main()
    {
    cout<<"Hello";
    return 0;
    }

  2. #2
    Registered User Aran's Avatar
    Join Date
    Aug 2001
    Posts
    1,301
    i'm no mac programming expert by any stretch of the imagination, but here are my thoughts on this:

    standard input in windows is the keyboard and standard output is the console window (or monitor). From what i have heard of mac, they have no DOS, so they can't have a console window to ouput stuff to. Have you tried using printf() and scanf()?

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    24
    heh. just out of interest have you ever used a Mac?

    the keyboard is still the primary input method and the monitor the primary output method, I'm pretty sure. But you're right that there is no DOS.

    printf() does the same thing as cout (ie prints to a file).

    I thought that's what it meant, the f in printf standing for file and cout meaning console out.

    Thanks anyway.

    Anyone else have any ideas?
    Last edited by quentin; 04-27-2002 at 09:26 AM.
    #include <iostream.h>
    int main()
    {
    cout<<"Hello";
    return 0;
    }

  4. #4
    Registered User
    Join Date
    Apr 2002
    Posts
    24
    all I really want to know is "Is cout supposed to print to a file?"
    #include <iostream.h>
    int main()
    {
    cout<<"Hello";
    return 0;
    }

  5. #5
    Pygmy Monkey ErionD's Avatar
    Join Date
    Feb 2002
    Posts
    408
    No.

  6. #6
    Registered User Aran's Avatar
    Join Date
    Aug 2001
    Posts
    1,301
    cout prints to standard output.. maybe you have to redefine what standard output is when you are attempting to write a console app on mac? i'm not sure... i don't think there are many mac users around here.. i'm not even sure if you are supposed to write console programs with a mac.

  7. #7
    Registered User
    Join Date
    Apr 2002
    Posts
    24
    well. I don't see why you shouldn't be able to write console apps on Mac but thanks anyway.

    I'll try and investigate this elsewhere as well.
    #include <iostream.h>
    int main()
    {
    cout<<"Hello";
    return 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. ? with cin and cout
    By Limming in forum C++ Programming
    Replies: 3
    Last Post: 08-18-2007, 11:32 AM
  2. Binary I/O with cin and cout
    By The Urchin in forum C++ Programming
    Replies: 4
    Last Post: 10-24-2006, 12:47 PM
  3. Overriding Cin with Cout
    By Tainted in forum C++ Programming
    Replies: 5
    Last Post: 10-06-2005, 02:57 PM
  4. I'm REALLY confused. Why isn't cout or cin working here?
    By niudago in forum C++ Programming
    Replies: 8
    Last Post: 02-15-2003, 04:53 PM
  5. i don't know about cin, cout, flag.
    By comwin in forum C++ Programming
    Replies: 2
    Last Post: 11-08-2001, 03:26 AM

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