Beginner Question about cout and cin

This is a discussion on Beginner Question about cout and cin within the C++ Programming forums, part of the General Programming Boards category; I have just started working on learning C++, got Microsoft Visual Basic C++ and a book which i am reading ...

  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    7

    Unhappy Beginner Question about cout and cin

    I have just started working on learning C++, got Microsoft Visual Basic C++ and a book which i am reading and working through. But now i have come upon a few problems i believe are actually easy to solve, but i am ignorant as to how.

    Firstly, Microsoft Visual Basic C++ does not seem to understand the lines:

    cout >>
    cin <<

    it brings them up as errors indicating that they are not actual reserved words.
    When i try to use them i use both <iostream.h> and <iomanip.h>, but perhaps there is a different one for this program?

    I also have the problem that Microsoft VB C++ does not recognize the #includes <graphics.h> or "apstring.h". Are these simply not used in this program or do they have a different name?

  2. #2
    Burning in Hell! Luigi's Avatar
    Join Date
    Nov 2002
    Posts
    117
    just type #include <iostream> no .h
    also type : using namespace std;

    finally:
    use cin >> not cin <<...
    also cout << not cout >>

    I think that should answer all your questions/problems
    Luigi


    // I use Xcode 1.1 && CodeWarrior 8.3
    // When on Mac Os X 10.3.2

    // I use Microsoft Visual C++ 6.0
    // When on windows XP

  3. #3
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    apstring.h is not a standard header file. it is made by CollegeBoard for APCS classes. You can find it here . The file must be in the same folder as your project, and you must include apstring.cpp in your project.

  4. #4
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    Firstly, Microsoft Visual Basic C++
    Are you using Visual C++ or Visual basic?? Visual Basic wont work because that is not a C++ compiler.

    try this:

    Code:
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
    int a;
    
    cout << "Enter a number: ";
    cin >> a;
    
    cout << "Number was: " << a << endl;
    return 0;
    }

  5. #5
    Registered User
    Join Date
    Jan 2003
    Posts
    648
    >Microsoft Visual Basic C++
    They are different languages. VB is one language, C++ is another. They are not the same.

    >#includes <graphics.h> or "apstring.h".
    Microsoft compilers do not support graphics.h. Use a borland compiler, although those libraries are old'en. For the ap classes, go into the school's compiler's directories and copy all the .h and .cpp files for the ap classes. Get your teacher to help you if you need it. Then, go into your computer, paste them there in some folder (use a floppy) and go into compiler options and add the directory of where you put them in. Boom, it should work.

  6. #6
    Registered User
    Join Date
    Apr 2003
    Posts
    7

    whew

    Thanks a lot for the help, now cout and cin are working but i have come upon quite an unusualy error message that perhaps someone here will understand:

    Compiling...
    IMPORTANT1.C
    c:\program files\microsoft visual studio\vc98\include\eh.h(32) : fatal error C1189: #error : "eh.h is only for C++!"
    Error executing cl.exe.

  7. #7
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    looks like u didnt comment off a line u mean too comment off

  8. #8
    Registered User
    Join Date
    Apr 2003
    Posts
    7
    its just a copy of the code pasted above by you RoD

  9. #9
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    it cant be, that error doesnt make any sense.

    try

    Code:
    #include <iostream.h>
    
    int main()
    {
    int a;
    cout << "Enter a number: ";
    cin >> a;
    cout << "Number was: " << a << endl;
    return 0;
    }

  10. #10
    Registered User
    Join Date
    Apr 2003
    Posts
    7
    hmmm wierd.

    If i use:
    #include <iostream>
    then i get that wierd error. I think it is BECAUSE i dont use the .h at the end.

    If i use:
    # include <iostream.h>
    It doesn't understand the following line of:
    using namespace std;
    or any cin or cout statements.

    So i am assuming now that i MUST put the .h, so there is still not really a solution to the original problem.

    Really starting to hate microsoft.....

  11. #11
    Burning in Hell! Luigi's Avatar
    Join Date
    Nov 2002
    Posts
    117
    If you use .h remove using namespace std;
    but better just usesomething else like borland c++ its free and better, well from what ive heard..
    Luigi


    // I use Xcode 1.1 && CodeWarrior 8.3
    // When on Mac Os X 10.3.2

    // I use Microsoft Visual C++ 6.0
    // When on windows XP

  12. #12
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    dont mix and match the two example i gave you, try them one at a time and see which works. I dont see how that last error you posted could have resulted from my first code example unless you modified it, its not possible if were using the same compiler. That error makes no sense at all.

  13. #13
    Registered User
    Join Date
    Apr 2003
    Posts
    7
    must be my computer, so I just broke down and emailed microsoft to play the waiting game.

    I copied your first example code exactly, still pops up that error.

    And i had no idea Borland C++ was free... well darnit....

    What exactly is cl.exe? that is apparently the part causing an error.
    Last edited by Dillius; 04-05-2003 at 06:13 PM.

  14. #14
    Registered User
    Join Date
    Mar 2003
    Posts
    26

    off topic, sorry

    Originally posted by RoD


    Code:
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
    int a;
    
    cout << "Enter a number: ";
    cin >> a;
    
    cout << "Number was: " << a << endl;
    return 0;
    }
    excuse me Rod but what does the two lines of code i made bold do, i wrote a simple program in the same fashion as the one above that would square a number you enter but didnt add what you wrote. what do they do? *thank you*

  15. #15
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    namespace :

    http://faq.cprogramming.com/cgi-bin/...&id=1043284351


    << endl;

    Creates a new line. What you are doing here is telling it to end the current line.

    So if i output this way:

    cout << "Hello World";
    cout << "Im Steve";

    the output would be Hello WorldIm Steve.

    If i do it this way:

    cout << "Hello World" << endl;
    cout << "Im Steve" << endl;

    it shows as

    Hello World
    Im Steve


    any clearer?

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

Similar Threads

  1. CIN Input count question?
    By kamran in forum C++ Programming
    Replies: 5
    Last Post: 10-24-2006, 05:06 PM
  2. Overriding Cin with Cout
    By Tainted in forum C++ Programming
    Replies: 5
    Last Post: 10-06-2005, 03:57 PM
  3. cin question
    By tinkerbell20 in forum C++ Programming
    Replies: 9
    Last Post: 06-10-2005, 02:23 AM
  4. Simple Question relating to the IOStream Lib and Cin
    By XcomvB in forum C++ Programming
    Replies: 6
    Last Post: 06-12-2003, 03:17 AM
  5. 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, 05:53 PM

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