CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 13 of 13

Thread: C++ basics

  1. #1
    Join Date
    Feb 2004
    Posts
    41

    C++ basics

    Hello.
    I am new to this board and to c++ , so i got couple basic questions to ask:
    1.Why do i have to use semicolon after class declaration:
    EX:
    class CError
    {
    public:

    };
    2.Why do we not need to use semicolons after writing code into functions, and after main?I mean,
    is there any particular reason for this to be this way , or is this just how c++ is?Is there a rule on
    where ";" are suppoused to be ?
    3.when you define a function fo some class ,you use :: before the functions name:
    void CTest::Function1()
    {
    }
    What are they for??What do they mean?
    4. What is the diffrence between | and ||??
    5. what is a string?
    and do i need to #include <string> to use "string teststring;"?
    6.does this line create an object of a ifstream class named fin.
    ifstream fin;
    7.why do we need a ifstream class object in this function:
    getline(fin, szLine);
    ??
    8.why do we use :: in something like std::somefunction. What is the meaning of it?
    9.What does this line mean: HWND hWndConsole = NULL;?? Why is it equal to NULL?
    10.In the next code snippet:
    char szTitle[MAX_PATH];
    GetConsoleTitle( szTitle, MAX_PATH );
    why does the array have max_path as a # of array items??i tried to chage it but it jsut says that the "newname" is not

    defined?
    11.HANDLE OutputH; this is a handle to a console inwod as i undrestadn..well what does that mean?
    12. also people say that a class in an object, but then what is the object that is done by:
    CTestClass objecthere;
    ?
    I know this is kind of a big post , but i am jsut starting out wiht C++ and i got some code snippets and here is some stuff

    that i do not undestand. I would really apriciate it so that somone could post an answer to this.
    Thx in advance
    Last edited by rvr_coder; February 19th, 2004 at 06:21 PM.

  2. #2
    Join Date
    Mar 2002
    Location
    California
    Posts
    1,582
    This sounds like an assignment. Many of these questions are easy to find. Please attempt to answer them yourself, and we'll be glad to help you with specifics.

  3. #3
    Join Date
    Feb 2004
    Posts
    41
    exectly where can i find them? i check the faq,.,,they are not there...i checked couple of books i got , i can't idn them there either.....and it is not an assignmnet...we get c+= in school only next year....it is just i have been doing some c++ project and used some code snippets from internet , and i don't get these parts.....

  4. #4
    Join Date
    Jul 2003
    Location
    Maryland
    Posts
    762
    Originally posted by rvr_coder
    and it is not an assignmnet...
    My butt it isn't.

    All of the questions are quite basic and if you read a C++ book, you would be able to get these answers quite easily. Actually, you'd probably only need to read a few chapters/pages.

    They probably arn't setup in the book like a normal textbox where it restartes the question and gives you the answer like you're probably looking for.

  5. #5
    Join Date
    Feb 2004
    Posts
    41
    this is not an assignment , if you can'r read, i don't have c++ till next year.....i read like 2 c++ books...and i didn';t get any answers at all...books are not too good...but i cna't get ay better ones at a moment....so could you please give at least some answers on some of them?

  6. #6
    Join Date
    Jul 2003
    Location
    Guayama, P.R.
    Posts
    41
    Well ... if you read 2 C++ books and you can't answer questions like #1, 2, 5, 7, 10, then those books are either crap or you are not reading, you are just browsing.

    Read the books well, you will be able to answer these questions.

    You can also visit this page for you to read:

    www.cplusplus.com/doc/tutorial/


    or you can just google for C++ information.

    Also visit this site:

    http://cplus.about.com/library/blcplustut.htm

  7. #7
    Join Date
    Feb 2004
    Posts
    41
    ok...i think i got question:1,2,3,5,6,8...thx for the resrouces...but i am stuill stuck with the left ones....
    #4
    i get that | is an bitwise inclusive or operater..i get that it means is that eiather or or and ?
    and i right?

    but i am still stuck with other ones..
    #10:
    i get that handle is a way for windows to comunicate with something.....how does it work?
    coutl somone give any thought on # 4, 7, 9, 10 and ?
    Last edited by rvr_coder; February 19th, 2004 at 07:35 PM.

  8. #8
    Join Date
    Jul 2003
    Location
    Guayama, P.R.
    Posts
    41
    || = or
    && = and

    7. why do we need a ifstream class object in this function:
    getline(fin, szLine);

    Again ... if you look well enough and really READ you can answer all that's left :

    Code exmaple using ifstream:

    Code:
    #include <fstream.h>
    #include <iostream.h>
    #include <stdlib.h>
    
    int main()
    {
     ifstream centrada;
     ofstream csalida;
     
     cout <<"Se comienza el procesamiento"<<endl;
     
        centrada.open("asterisco.dat");
        if (centrada.fail())
        {
            cout << "Input file opening failed.\n";
            exit(1);
        }
        
        csalida.open("salida.dat");
        if (centrada.fail())
        {
            cout << "Input file opening failed.\n";
            exit(1);
        }
       
        char prox;
        
        centrada.get(prox);
        while( !centrada.eof())
        
         {
            if (prox == '*')
             {
              cout<<" ";
              csalida.put(prox);
              centrada.get(prox);
              
             }
            
            else
             {
              cout<<prox;
               
              csalida.put(prox);
              
              centrada.get(prox);
             } 
             
         }
         
         centrada.close();
         csalida.close();
         
       return 0;
      }
    In here, instead of getline, we use .get.

  9. #9
    Join Date
    Feb 2004
    Posts
    41
    ok..thx , that is a great help to my..cna somone tell me about 9 and 10...also what does | mena if it is not or/and......?
    thx

  10. #10
    Join Date
    Feb 2003
    Posts
    377
    7. Actually, I'm not sure eagle1 really answered 7.

    First, for getline, you just need an istream, not necessarily an ifstream (the input stream does not have to be a file stream). The getline function you are referring to gets input and places it into a string. It is not a member function, so it doesn't know where you want to the input from. For example, you can get input from a file or from the console (cin):
    Code:
    #include <iostream>
    #include <fstream>
    #include <string>
    
    int main()
    {
        std::string szLine;
    
        // Read from the console.
        std::getline(std::cin, szLine);
    
        // Read from a file.
        std::ifstream fin("input.txt");
        std::getline(fin, szLine);
    }

  11. #11
    Join Date
    Feb 2004
    Posts
    41
    hmm...this is interesting...so we use fin..to show that it uses a stream....to read from file??
    thx....
    could somone alos get an opinion on my previous post....
    also i don't yet get number 10 and 12.......
    thx in advance
    Last edited by rvr_coder; February 19th, 2004 at 08:16 PM.

  12. #12
    Join Date
    Jul 2003
    Location
    Guayama, P.R.
    Posts
    41
    Actually, I'm not sure eagle1 really answered 7.
    LOL. I actually want him to look for the answers!!!
    Like, what fun will he have if I say that MAX_PATH is a global variable already defined?

  13. #13
    Join Date
    Feb 2004
    Posts
    41
    i think i got that MAX_PATH is a global predefines variable but when i try to use other ones in thouse series..it deosn't work...
    _MAX_DIR Maximum length of directory component
    _MAX_DRIVE Maximum length of drive component
    _MAX_EXT Maximum length of extension component
    _MAX_FNAME Maximum length of filename component
    _MAX_PATH Maximum length of full path
    why does it only work with MAX_PATH ?????
    what is the diffrence between them....?
    also anyone knows what are libraries for? like in dev-Cpp there is a lib folder with files like libwinmm.a ....i use them to be able to use stuff like PLaySound...but what are they in themselves?
    Last edited by rvr_coder; February 19th, 2004 at 08:40 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured