Thread: questions

  1. #1
    Registered User
    Join Date
    Dec 2005
    Location
    Canada
    Posts
    267

    questions

    1.are windows.h and iostream standard headers?

    2.1.How's the hexadecimal escape sequence used?
    2.2.is it \xdd or \xnnn? I saw \xdd somewhere, i think a book and \xnnn here

    3.is either one of these a better habit when using braces? I'm used to doing the first one:
    Code:
    int main(){ //having the first bracket here
         //body...
    }
    or
    Code:
    int main()
    { //having the first bracket here
         //body...
    }
    4.What's flush do?
    Last edited by h_howee; 12-31-2005 at 06:25 PM. Reason: 4

  2. #2
    Registered User
    Join Date
    Nov 2004
    Location
    Pennsylvania
    Posts
    434
    well they are headers. Depends on what you are programming but if you are doing console apps you will certainly always (i cant think of an exception) iostream. If you need some of the other features included in windows.h like Sleep() and such then you need that too.

    Another question i can answer is your last one there, it doesnt matter which way you put it, its a personal preference, i use the second way as do most people, its really up to you so long as the brackets come after the parentheses in main.

    Good luck!

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    1. <iostream> is a standard C++ header. <Windows.h> is a platform specific header for Windows programming, and is not part of standard C++.

    3. The bracket placement is a style issue. Pick a style and be consistent, it does not matter which you choose. Make sure you are using the same style as everybody else working on your project.

  4. #4
    Registered User
    Join Date
    Dec 2005
    Location
    Canada
    Posts
    267
    and how is "hex" used?

  5. #5
    C(++)(#)
    Join Date
    Jul 2004
    Posts
    309
    Quote Originally Posted by h_howee
    and how is "hex" used?
    Hex is a numbering system (like the commonly used decimal system), that is base 16 instead of base 10.

    Usually prefixed with a 0x, or suffixed with an 'h', Hex can be used to make binary easier to read:
    Code:
    00000011 //This is 3 in binary
    0x3 //3 in Hex
    0x3 is a lot easier to read than the binary version.

    More information can be found here
    To code is divine

  6. #6
    Registered User
    Join Date
    Dec 2005
    Location
    Canada
    Posts
    267
    I don't think you understood correctly, i meant hex as in here and same thing for flush:

    Code:
    cout << hex << i << flush;
    does this display i in hexadecimal?

  7. #7
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318

    Cool

    assuming you mean ios::hex, then yes that is the C++ way to print i in hex.

  8. #8
    Registered User
    Join Date
    Dec 2005
    Location
    Canada
    Posts
    267
    how do i change the window buffer size?
    I took part of this code from one of the posts and change dit a bit, sometimes it changes the window size, sometimes it changes the screen buffer size:

    Code:
    #include <iostream>
    #include <windows.h>
    
    using namespace std;
    
    int main()
    {
    HWND hWnd;
    hWnd = FindWindow(NULL, "test");
    HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
    COORD NewSBSize = GetLargestConsoleWindowSize(hOut);
    SMALL_RECT DisplayArea = {0, 0, 0, 0};
    
    for (;;){
        cin>>NewSBSize.X>>NewSBSize.Y;
        DisplayArea.Right = NewSBSize.X - 1;
        DisplayArea.Bottom = NewSBSize.Y - 1;
        
        SetConsoleWindowInfo(hOut, TRUE, &DisplayArea);
        SetConsoleScreenBufferSize(hOut, NewSBSize);
    }
    
    ShowWindow(hWnd, SW_MAXIMIZE);
    return 0;
    }




    Ok, i fixed the problem, for some reason it had the same problem as cin.get() where i have to put them in twice...
    Last edited by h_howee; 01-05-2006 at 02:25 PM. Reason: problem fixed

  9. #9
    Rabble Rouser Slacker's Avatar
    Join Date
    Dec 2005
    Posts
    116
    >1.are windows.h and iostream standard headers?
    Standard for what? windows.h is a standard Win32 API header, and iostream is a standard C++ header.

    >2.1.How's the hexadecimal escape sequence used?
    \xhh, where h is a hexadecimal digit. The number of digits allowed depends on the size of a character. If CHAR_BIT is 8 then two digits makes sense because the largest value that 8 bits can hold is 0xFF, right?

    >3.is either one of these a better habit when using braces?
    No, and anyone that tells you otherwise is probably a smidge too stuffy to be any fun.

    >4.What's flush do?
    Flushing an output stream means dumping the contents of the stream's buffer to the device that the stream writes to. In the case of cout, for instance, flushing guarantees that the output will be written to the screen right then and there instead of when the buffer is filled. A request for input on a stream tied with the output stream will also force a flush, so you don't need to call flush often if you're working with cin and cout. That's one reason people might suggest you use '\n' instead of endl, because endl also flushes the stream, often unnecessarily.

    For the nitpickers here, that's assuming that standard output points to a screen.

  10. #10
    Registered User
    Join Date
    Jun 2003
    Posts
    91
    1) <iostream> is part of the standard C++ library http://en.wikipedia.org/wiki/C%2B%2B_standard_library

    <windows.h> Part of Microsofts win32 api library http://en.wikipedia.org/wiki/Windows_API

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. questions....so many questions about random numbers....
    By face_master in forum C++ Programming
    Replies: 2
    Last Post: 07-30-2009, 08:47 AM
  2. A very long list of questions... maybe to long...
    By Ravens'sWrath in forum C Programming
    Replies: 16
    Last Post: 05-16-2007, 05:36 AM
  3. Several Questions, main one is about protected memory
    By Tron 9000 in forum C Programming
    Replies: 3
    Last Post: 06-02-2005, 07:42 AM
  4. Trivial questions - what to do?
    By Aerie in forum A Brief History of Cprogramming.com
    Replies: 23
    Last Post: 12-26-2004, 09:44 AM
  5. questions questions questions.....
    By mfc2themax in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 08-14-2001, 07:22 AM