Thread: Understanding C++ Online References

  1. #1
    System.out.println("");
    Join Date
    Jan 2005
    Posts
    84

    Understanding C++ Online References

    That may be a poorly worded title, but this is what I am confused about. The only online reference I use for C++ is this website:

    http://www.cppreference.com/

    When I look functions up, it doesn't seem to tell me everything that is available. For instance, when looking the transform function here:

    http://www.cppreference.com/cppalgorithm/transform.html

    this is the prototype:

    Code:
    #include <algorithm>
    iterator transform( iterator start, iterator end, iterator result, UnaryFunction f );
    iterator transform( iterator start1, iterator end1, iterator start2, iterator result, BinaryFunction f );
    What exactly is UnaryFunction f? I know that a unary function is something that operates on only one member (unlike binary operators addition, multiplication, etc). From other code, I have seen that tolower and toupper work there when operating on strings, but what else is available?

    For a day or two I messed around with Windows programming and when searching the MSDN is seemed to explicitly say what options could be placed there. Are there any sites like that are a general C++ reference site and not specific to windows programming?

    It seems like the biggest hurdle to programming is understanding the documentation. There certainly isn't a lack of it out there. It's just getting to the point where it all makes sense and you can understand it.

    Check this code out:

    Code:
    // An improved version of the program! ^_^ Good mood...
    #include <iostream>
    #include <string>
    
    int main (void) 
    {
    
       std::string answer = "twenty";
       std::cout << "How many apples did I buy? (word answers):";
       std::cin >> answer;
    
       transform(answer.begin(), answer.end(), answer.begin(), tolower);
    
       if(answer != "twenty")
       {
           std::cout << "Sorry, you're wrong\n";
       }
       else 
       {
           std::cout << "Yes, that's correct\n";
       }
       
       
       std::cin.ignore();
       std::cin.get();
    }
    One more quick question.
    Why does this code work without me including the algorithm header? Is it automatically included with the string header?

    Thank you.

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >What exactly is UnaryFunction f?
    A template parameter name. It basically means that a function or function object that can take one argument is expected.

    >Are there any sites like that are a general C++ reference site and not specific to windows programming?
    I'm not sure what you mean by "like that", but I prefer Dinkumware's reference when I don't have the standard on me.

    >Is it automatically included with the string header?
    Or the iostream header, but you shouldn't rely on that.
    My best code is written with the delete key.

  3. #3
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    I find that reference site to be incomplete anyway. Check out http://www.sgi.com/tech/stl/table_of_contents.html see if it works for you. While it's not as orgaized into subsections as the other one, it has much more information.

  4. #4
    Registered User
    Join Date
    Mar 2006
    Posts
    725
    The STL operates on a higher level of abstraction; it makes use of concepts. Eg. BinaryFunction is simply a function which takes two arguments of some type and returns a value. It doesn't even need to be a normal function; you can pass a function pointer or even object.

    The code snippet will not or should not compile:
    <algorithm> is not included
    transform() is in std::
    Code:
    #include <stdio.h>
    
    void J(char*a){int f,i=0,c='1';for(;a[i]!='0';++i)if(i==81){
    puts(a);return;}for(;c<='9';++c){for(f=0;f<9;++f)if(a[i-i%27+i%9
    /3*3+f/3*9+f%3]==c||a[i%9+f*9]==c||a[i-i%9+f]==c)goto e;a[i]=c;J(a);a[i]
    ='0';e:;}}int main(int c,char**v){int t=0;if(c>1){for(;v[1][
    t];++t);if(t==81){J(v[1]);return 0;}}puts("sudoku [0-9]{81}");return 1;}

  5. #5
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    I also find that cppreference.com isn't the best. I usually use google, not a particular reference.

    Man pages are often a good reference. Googling for "man function" often works.

    Also see this: http://cboard.cprogramming.com/showp...67&postcount=9
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  6. #6
    System.out.println("");
    Join Date
    Jan 2005
    Posts
    84
    Thanks for the help.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Error in distributing .exe online
    By GamesSmash in forum C++ Programming
    Replies: 31
    Last Post: 11-27-2007, 04:41 PM
  2. 2D Spaceship shooter online - Need 2 keen programmers
    By drallstars in forum Projects and Job Recruitment
    Replies: 1
    Last Post: 05-19-2005, 07:40 AM