Draw the value on screen?

This is a discussion on Draw the value on screen? within the C++ Programming forums, part of the General Programming Boards category; hi im new to c++ and im using bloodshed dev-c++, and i want to know how to set a variable ...

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    28

    Draw the value on screen?

    hi im new to c++ and im using bloodshed dev-c++, and i want to know how to set a variable to 50 and then display it on the screen. could someone plz help

  2. #2
    Registered User
    Join Date
    May 2006
    Posts
    903
    Code:
    int var = 50;
    std::cout << var;
    You're better off reading a tutorial if you don't know this.

  3. #3
    Registered User
    Join Date
    May 2006
    Posts
    28
    when i write that it says project is not compiled but i did compile it..

  4. #4
    Registered User
    Join Date
    Oct 2005
    Posts
    271
    Code:
    #include <iostream>
    
    int main()
    {
    
    int var = 50; std::cout << var; return 0;
    }

  5. #5
    Registered User
    Join Date
    May 2006
    Posts
    28
    the screen just pops up and then disappers...

  6. #6
    Registered User
    Join Date
    May 2006
    Posts
    903
    Dude, read a tutorial on the site. I don't want to sound harsh, but we're not going to give you lessons, we will help you with whatever issue / bug / problem / question -- that isn't asking for us to give you code -- but please show some effort.

    Edit: Add this line before 'return 0;'
    Code:
    std::cin.get();

  7. #7
    Registered User mrafcho001's Avatar
    Join Date
    Jan 2005
    Posts
    483
    Code:
    #include <iostream>
    
    int main()
    {
    
        int var = 50;
        std::cout << var;
        system("PAUSE");
        return 0;   
    }
    My Website
    010000110010101100101011
    Add Color To Your Code!

  8. #8
    Registered User
    Join Date
    May 2006
    Posts
    903
    This is some evil code, mrafcho001...

  9. #9
    Registered User
    Join Date
    May 2006
    Posts
    28
    thank you!@

    Code:
    #include <iostream>
    
    int main()
    {
    
        int var = 50;
        std::cout << var;
        system("PAUSE");
        return 0;   
    }
    This is some evil code, mrafcho001...
    evil? what does that code do?

  10. #10
    Registered User
    Join Date
    May 2006
    Posts
    903
    It's evil only because system() is a portable function (which is good because it is cross-compiler and cross-platform) which takes in non-portable arguments (which means that this line wouldn't work under any OS that doesn't define "PAUSE" -- which is bad). My code on the other hand does more or less the same job and is completely cross-platform and cross-compiler.

  11. #11
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,762
    The problem is with system("PAUSE"); which has many issues.
    - it's operating system dependant. System gets the operating system to spawn another program to do what your asking. You are making the assumption that the pause program exists on the computer, which may not be true.
    - it's slow. The operating system has to find the program and run it, when it might not exist.
    - it's dangerous. Someone could have replaced the "pause" program, or mapped it to another dangerous program that does god-knows-what, and the program you made can't tell the difference. Therefore hackers can easily get access to other parts of the computer.

  12. #12
    Registered User
    Join Date
    May 2006
    Posts
    28
    so i shouldn't use
    Code:
    system("pause");
    and use
    Code:
    std::cin.get();
    right?

  13. #13
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,762
    Try to avoid using system() ever, in fact.

  14. #14
    Registered User
    Join Date
    May 2006
    Posts
    903
    Quote Originally Posted by k1ll3r
    so i shouldn't use
    Code:
    system("pause");
    and use
    Code:
    std::cin.get();
    right?
    Yes.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How does MS Excel or Word draw to the screen??
    By Fremontknight1 in forum Windows Programming
    Replies: 2
    Last Post: 07-20-2008, 02:58 PM
  2. Feedback: Functional Specification Wording
    By Ragsdale85 in forum C++ Programming
    Replies: 0
    Last Post: 01-18-2006, 04:56 PM
  3. SDL segfault when trying to draw to screen
    By Blizzarddog in forum Game Programming
    Replies: 2
    Last Post: 12-09-2005, 07:53 AM
  4. char copy
    By variable in forum C Programming
    Replies: 8
    Last Post: 02-06-2005, 10:18 PM
  5. i am not able to figure ot the starting point of this
    By youngashish in forum C++ Programming
    Replies: 7
    Last Post: 10-07-2004, 03:41 AM

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