I need some translations from C to C++

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nestle
    New Member
    • Oct 2009
    • 15

    I need some translations from C to C++

    Just these:
    printf();
    scanf();
    fread();
    fwrite();
  • newb16
    Contributor
    • Jul 2008
    • 687

    #2
    #include <stdio>
    std::printf(... );
    ?

    Comment

    • JonathanS
      New Member
      • Jan 2008
      • 37

      #3
      Should be #include <cstdio> I think.

      He or she might be asking for cout/cin in place of printf/scanf? But like newb said if you really want to use the original c functions just use them directly in your C++ prog.

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        Originally posted by newb16
        #include <stdio>
        std::printf(... );
        ?

        Nope. What you show is C plus there is no <stdio> include. I believe you meant <cstdio>.

        To the OP:

        The functions you mention are replaced by operator<< and operator>> depending upon whether you are insrtingor extracting data from a stream.

        The functions you mention can be used only with the built-on types of C whereas the operator<< and operator>> can be written by you to work woth any type of object.

        Comment

        • nestle
          New Member
          • Oct 2009
          • 15

          #5
          Originally posted by weaknessforcats
          Nope. What you show is C plus there is no <stdio> include. I believe you meant <cstdio>.

          To the OP:

          The functions you mention are replaced by operator<< and operator>> depending upon whether you are insrtingor extracting data from a stream.

          The functions you mention can be used only with the built-on types of C whereas the operator<< and operator>> can be written by you to work woth any type of object.
          Well if you would be so kind as to tell me what those functions are exactly?
          Like printf("Hello world");
          How do I write it with the << >> operators?

          Comment

          • RedSon
            Recognized Expert Expert
            • Jan 2007
            • 4980

            #6
            Code:
            cout << "Hello World";

            Comment

            • nestle
              New Member
              • Oct 2009
              • 15

              #7
              Originally posted by RedSon
              Code:
              cout << "Hello World";
              Thanks.
              Now how about the other 3 functions?

              Comment

              • RedSon
                Recognized Expert Expert
                • Jan 2007
                • 4980

                #8
                scanf would be
                Code:
                cin >> var;
                And for the rest it is the same just use a file stream instead of cout and cin. Or even better, you could use google to help you look up usage!

                Comment

                Working...