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; using namespace std: makes it possible to call/use functions within standardized headers like <iostream>. If you dont type it youll ...

  1. #16
    Burning in Hell! Luigi's Avatar
    Join Date
    Nov 2002
    Posts
    117
    using namespace std: makes it possible to call/use functions within standardized headers like <iostream>.

    If you dont type it youll have to add std::

    like this std::cin or std::endl etc...

    endl is just like /n plus it flush the buffer..
    so it will act like enter... just change line..
    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

  2. #17
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109

    Re: whew

    Originally posted by Dillius
    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.
    first thing i noticed. you are getting this error because the file is a c source file, not a c++ source file. the file should be .cpp not .c .

    edit: .cpp and use RoDs first code snippet.

  3. #18
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    One more thing. As you will notice, C++ will automatically drop down a line after you read in a variable, example.

    cout << "Enter a number: ";
    cin >> somevariable;

    cout << "You entered a number!";

    Now those cout lines will not display on the same line, but rather the second cout will be under the first just like if we used an endl, because cin >> flushes the buffer.

  4. #19
    Registered User
    Join Date
    Apr 2003
    Posts
    7
    Thanks a lot to everyone who helped me out, its all working fine now and i learned a lot from it.

    Yea the reason i was .c ending it was that was the only thing i remembered from reading another book, a dummies book for C, but now i do think back it was just C not C++.

    Makes me feel foolish, but you learn from your mistakes

    One final thing, anyone know offhand what #include to add for the purpose of drawing lines? graphics.h doesn't work for Microsoft version
    Last edited by Dillius; 04-05-2003 at 05:38 PM.

  5. #20
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    hmmm you could always get into opengl : )

  6. #21
    Registered User
    Join Date
    Apr 2003
    Posts
    7
    Well it really seems this book was not designed for learning C++ through microsoft visual C++, soooo.

    I just gonna throw out some more questions.

    Still wondering what the include is to use draw comands such as:
    lineto
    circle
    etc.

    and also if this following piece of code is valid for this software, i cant test it myself until i know what the include to replace graphic.h is:

    int graphdriver = DETECT, graphmode;
    initgraph(&graphdriver, &graphmode, "c:..\\bgi");

    Hate to be puttin so many questions up but honestly half the people i know dont even know how to turn a computer on......

  7. #22
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    int graphdriver = DETECT, graphmode;
    initgraph(&graphdriver, &graphmode, "c:..\\bgi");

    I'm no expert, but I don't recognize either of those lines as C++ code, so even if you find the right header file, I don't believe those lines will work.

  8. #23
    Registered User
    Join Date
    Feb 2003
    Posts
    7

    i think i can help

    I just did a box for c++ it sucked but i finally got it.



    code

    #include<iostream.h>
    #include<conio.h>

    int column;

    int ledger()
    {
    cout << "\xDA";
    for(column = 2; column < 75 ; ++column)//for the top line
    {
    cout << "\xC4";
    }

    gotoxy(75,1);
    cout << "\xBF\n";
    for(column = 2; column < 24; ++column) //for the right side
    {
    gotoxy(1, column);
    cout << "\xB3";
    }
    for(column = 2; column < 24; ++column) //for the left side
    {
    gotoxy(75, column);
    cout << "\xB3";
    }
    gotoxy(1, 24);
    cout << "\xC0";
    for(column = 2; column < 75; ++column) //for the bottom line
    {
    cout << "\xC4";
    }
    gotoxy(1, 4);
    cout << "\xC0";
    for(column = 2; column < 75; ++column) //for the header line
    {
    cout << "\xC4";
    }
    gotoxy(2, 3);
    cout << "Number";
    gotoxy(9, 1);
    for(column = 2; column < 24; ++column) //for the first column
    {
    gotoxy(9, column);
    cout << "\xB3";
    }
    gotoxy(10, 3);
    cout << "Date";
    gotoxy(15, 1);
    for(column = 2; column < 24; ++column) //for the second column
    {
    gotoxy(15, column);
    cout << "\xB3";
    }
    gotoxy(16, 3);
    cout << " Description";
    gotoxy(40, 1);
    for(column = 2; column < 24; ++column) //for the third column
    {
    gotoxy(40, column);
    cout << "\xB3";
    }
    gotoxy(42, 1);
    for(column = 2; column < 24; ++column) //for the fourth column
    {
    gotoxy(42, column);
    cout << "\xB3";
    }
    gotoxy(43, 3);
    cout << "Payment";
    gotoxy(50, 1);
    for(column = 2; column < 24; ++column) //for the fifth column
    {
    gotoxy(50, column);
    cout << "\xB3";
    }
    gotoxy(52, 1);
    for(column = 2; column < 24; ++column) //for the checkoff column1
    {
    gotoxy(52, column);
    cout << "\xB3";
    }
    gotoxy(53,3);
    cout << "Deposit";
    gotoxy(62, 1);
    for(column = 2; column < 24; ++column) //for the checkoff column1
    {
    gotoxy(62, column);
    cout << "\xB3";
    }
    {
    gotoxy(63, 3);
    cout << "Balance";
    }
    gotoxy(1, 6);
    cout << "\xC0";
    for(column = 2; column < 75; ++column) //for the first entry
    {
    cout << "\xC4";
    }
    gotoxy(1, 8);
    cout << "\xC0";
    for(column = 2; column < 75; ++column) //for the second entry
    {
    cout << "\xC4";
    }
    gotoxy(1, 10);
    cout << "\xC0";
    for(column = 2; column < 75; ++column) //for the third entry
    {
    cout << "\xC4";
    }
    gotoxy(1, 12);
    cout << "\xC0";
    for(column = 2; column < 75; ++column) //for the fourth entry
    {
    cout << "\xC4";
    }
    gotoxy(1, 14);
    cout << "\xC0";
    for(column = 2; column < 75; ++column) //for the fifth entry
    {
    cout << "\xC4";
    }
    gotoxy(1, 16);
    cout << "\xC0";
    for(column = 2; column < 75; ++column) //for the sixth entry
    {
    cout << "\xC4";
    }
    gotoxy(1, 18);
    cout << "\xC0";
    for(column = 2; column < 75; ++column) //for the seventh entry
    {
    cout << "\xC4";
    }
    gotoxy(1, 20);
    cout << "\xC0";
    for(column = 2; column < 75; ++column) //for the eighth entry
    {
    cout << "\xC4";
    }
    gotoxy(1, 22);
    cout << "\xC0";
    for(column = 2; column < 75; ++column) //for the ninth entry
    {
    cout << "\xC4";
    }
    gotoxy(75, 24);
    cout << "\xD9";
    {

Page 2 of 2 FirstFirst 12
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, 04:06 PM
  2. Overriding Cin with Cout
    By Tainted in forum C++ Programming
    Replies: 5
    Last Post: 10-06-2005, 02:57 PM
  3. cin question
    By tinkerbell20 in forum C++ Programming
    Replies: 9
    Last Post: 06-10-2005, 01: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, 02: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, 04:53 PM

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