What does the g stand for in gcount, tellg and seekg?











up vote
58
down vote

favorite
5












What does the g stand for in std::iostream's gcount, tellg and seekg members? And the p in pcount, tellp and seekp?



Why aren't they called just count, tell and seek?










share|improve this question




















  • 5




    It it was called only plain seek (for example), then you can't have separate pointers for the input and output parts of a combined input-and-output stream.
    – Some programmer dude
    Dec 4 at 8:30








  • 1




    By the way: The answers explain the p too. It may be more useful to edit the question for the p.
    – user202729
    Dec 4 at 10:53















up vote
58
down vote

favorite
5












What does the g stand for in std::iostream's gcount, tellg and seekg members? And the p in pcount, tellp and seekp?



Why aren't they called just count, tell and seek?










share|improve this question




















  • 5




    It it was called only plain seek (for example), then you can't have separate pointers for the input and output parts of a combined input-and-output stream.
    – Some programmer dude
    Dec 4 at 8:30








  • 1




    By the way: The answers explain the p too. It may be more useful to edit the question for the p.
    – user202729
    Dec 4 at 10:53













up vote
58
down vote

favorite
5









up vote
58
down vote

favorite
5






5





What does the g stand for in std::iostream's gcount, tellg and seekg members? And the p in pcount, tellp and seekp?



Why aren't they called just count, tell and seek?










share|improve this question















What does the g stand for in std::iostream's gcount, tellg and seekg members? And the p in pcount, tellp and seekp?



Why aren't they called just count, tell and seek?







c++ iostream






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 5 at 12:41









Tu.ma

804218




804218










asked Dec 4 at 8:28









Andrew Tomazos

34.8k25131224




34.8k25131224








  • 5




    It it was called only plain seek (for example), then you can't have separate pointers for the input and output parts of a combined input-and-output stream.
    – Some programmer dude
    Dec 4 at 8:30








  • 1




    By the way: The answers explain the p too. It may be more useful to edit the question for the p.
    – user202729
    Dec 4 at 10:53














  • 5




    It it was called only plain seek (for example), then you can't have separate pointers for the input and output parts of a combined input-and-output stream.
    – Some programmer dude
    Dec 4 at 8:30








  • 1




    By the way: The answers explain the p too. It may be more useful to edit the question for the p.
    – user202729
    Dec 4 at 10:53








5




5




It it was called only plain seek (for example), then you can't have separate pointers for the input and output parts of a combined input-and-output stream.
– Some programmer dude
Dec 4 at 8:30






It it was called only plain seek (for example), then you can't have separate pointers for the input and output parts of a combined input-and-output stream.
– Some programmer dude
Dec 4 at 8:30






1




1




By the way: The answers explain the p too. It may be more useful to edit the question for the p.
– user202729
Dec 4 at 10:53




By the way: The answers explain the p too. It may be more useful to edit the question for the p.
– user202729
Dec 4 at 10:53












2 Answers
2






active

oldest

votes

















up vote
71
down vote













In streams supporting both read and write, you actually have two positions, one for read (i.e. "get" denoted by "g") and one for write (i.e. "put" denoted by a "p").



And that's why you have a seekp (inherited from basic_ostream), and a seekg (inherited from basic_istream).



Side note: The language C has - in contrast to C++ - only one such function fseek for both pointers; There it is necessary to re-position the pointer when switching from read to write and vice versa (cf., for example, this answer). To avoid this, C++ offers separate functions for read and write, respectively.






share|improve this answer






























    up vote
    47
    down vote













    C++ offers two pointers while navigating the file: the get pointer and the put pointer. The first one is used for read operations, the second one for write operations.





    • seekg() is used to move the get pointer to a desired location with respect to a reference point.


    • tellg() is used to know where the get pointer is in a file.


    • seekp() is used to move the put pointer to a desired location with respect to a reference point.


    • tellp() is used to know where the put pointer is in a file.





    Main source: Quora, answer by Gunjan B. Yadav on Dec 1, 2017.






    share|improve this answer



















    • 12




      Why do C++ standards people name APIs as if keyboards have per-keystroke costs. 🙄
      – Alexander
      Dec 5 at 0:33








    • 10




      @Alexander : to avoid people getting paid by keystroke, obviously. Clever and business-oriented programmers naturally overcome this problem by inventing their own types and wrappers for the standard library, which of course always works out perfectly and has no disadvantages whatsoever.
      – Daniel Kamil Kozar
      Dec 5 at 0:35










    • @DanielKamilKozar Haha, I had a good chuckle.
      – Alexander
      Dec 5 at 0:39










    • @Alexander en.cppreference.com/w/cpp/chrono/high_resolution_clock
      – Ajay
      Dec 5 at 7:09












    • @Ajay I like it!
      – Alexander
      Dec 5 at 18:41











    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53608590%2fwhat-does-the-g-stand-for-in-gcount-tellg-and-seekg%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    71
    down vote













    In streams supporting both read and write, you actually have two positions, one for read (i.e. "get" denoted by "g") and one for write (i.e. "put" denoted by a "p").



    And that's why you have a seekp (inherited from basic_ostream), and a seekg (inherited from basic_istream).



    Side note: The language C has - in contrast to C++ - only one such function fseek for both pointers; There it is necessary to re-position the pointer when switching from read to write and vice versa (cf., for example, this answer). To avoid this, C++ offers separate functions for read and write, respectively.






    share|improve this answer



























      up vote
      71
      down vote













      In streams supporting both read and write, you actually have two positions, one for read (i.e. "get" denoted by "g") and one for write (i.e. "put" denoted by a "p").



      And that's why you have a seekp (inherited from basic_ostream), and a seekg (inherited from basic_istream).



      Side note: The language C has - in contrast to C++ - only one such function fseek for both pointers; There it is necessary to re-position the pointer when switching from read to write and vice versa (cf., for example, this answer). To avoid this, C++ offers separate functions for read and write, respectively.






      share|improve this answer

























        up vote
        71
        down vote










        up vote
        71
        down vote









        In streams supporting both read and write, you actually have two positions, one for read (i.e. "get" denoted by "g") and one for write (i.e. "put" denoted by a "p").



        And that's why you have a seekp (inherited from basic_ostream), and a seekg (inherited from basic_istream).



        Side note: The language C has - in contrast to C++ - only one such function fseek for both pointers; There it is necessary to re-position the pointer when switching from read to write and vice versa (cf., for example, this answer). To avoid this, C++ offers separate functions for read and write, respectively.






        share|improve this answer














        In streams supporting both read and write, you actually have two positions, one for read (i.e. "get" denoted by "g") and one for write (i.e. "put" denoted by a "p").



        And that's why you have a seekp (inherited from basic_ostream), and a seekg (inherited from basic_istream).



        Side note: The language C has - in contrast to C++ - only one such function fseek for both pointers; There it is necessary to re-position the pointer when switching from read to write and vice versa (cf., for example, this answer). To avoid this, C++ offers separate functions for read and write, respectively.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Dec 5 at 6:14









        Alex Taylor

        5,39021533




        5,39021533










        answered Dec 4 at 8:32









        Stephan Lechner

        25.2k21839




        25.2k21839
























            up vote
            47
            down vote













            C++ offers two pointers while navigating the file: the get pointer and the put pointer. The first one is used for read operations, the second one for write operations.





            • seekg() is used to move the get pointer to a desired location with respect to a reference point.


            • tellg() is used to know where the get pointer is in a file.


            • seekp() is used to move the put pointer to a desired location with respect to a reference point.


            • tellp() is used to know where the put pointer is in a file.





            Main source: Quora, answer by Gunjan B. Yadav on Dec 1, 2017.






            share|improve this answer



















            • 12




              Why do C++ standards people name APIs as if keyboards have per-keystroke costs. 🙄
              – Alexander
              Dec 5 at 0:33








            • 10




              @Alexander : to avoid people getting paid by keystroke, obviously. Clever and business-oriented programmers naturally overcome this problem by inventing their own types and wrappers for the standard library, which of course always works out perfectly and has no disadvantages whatsoever.
              – Daniel Kamil Kozar
              Dec 5 at 0:35










            • @DanielKamilKozar Haha, I had a good chuckle.
              – Alexander
              Dec 5 at 0:39










            • @Alexander en.cppreference.com/w/cpp/chrono/high_resolution_clock
              – Ajay
              Dec 5 at 7:09












            • @Ajay I like it!
              – Alexander
              Dec 5 at 18:41















            up vote
            47
            down vote













            C++ offers two pointers while navigating the file: the get pointer and the put pointer. The first one is used for read operations, the second one for write operations.





            • seekg() is used to move the get pointer to a desired location with respect to a reference point.


            • tellg() is used to know where the get pointer is in a file.


            • seekp() is used to move the put pointer to a desired location with respect to a reference point.


            • tellp() is used to know where the put pointer is in a file.





            Main source: Quora, answer by Gunjan B. Yadav on Dec 1, 2017.






            share|improve this answer



















            • 12




              Why do C++ standards people name APIs as if keyboards have per-keystroke costs. 🙄
              – Alexander
              Dec 5 at 0:33








            • 10




              @Alexander : to avoid people getting paid by keystroke, obviously. Clever and business-oriented programmers naturally overcome this problem by inventing their own types and wrappers for the standard library, which of course always works out perfectly and has no disadvantages whatsoever.
              – Daniel Kamil Kozar
              Dec 5 at 0:35










            • @DanielKamilKozar Haha, I had a good chuckle.
              – Alexander
              Dec 5 at 0:39










            • @Alexander en.cppreference.com/w/cpp/chrono/high_resolution_clock
              – Ajay
              Dec 5 at 7:09












            • @Ajay I like it!
              – Alexander
              Dec 5 at 18:41













            up vote
            47
            down vote










            up vote
            47
            down vote









            C++ offers two pointers while navigating the file: the get pointer and the put pointer. The first one is used for read operations, the second one for write operations.





            • seekg() is used to move the get pointer to a desired location with respect to a reference point.


            • tellg() is used to know where the get pointer is in a file.


            • seekp() is used to move the put pointer to a desired location with respect to a reference point.


            • tellp() is used to know where the put pointer is in a file.





            Main source: Quora, answer by Gunjan B. Yadav on Dec 1, 2017.






            share|improve this answer














            C++ offers two pointers while navigating the file: the get pointer and the put pointer. The first one is used for read operations, the second one for write operations.





            • seekg() is used to move the get pointer to a desired location with respect to a reference point.


            • tellg() is used to know where the get pointer is in a file.


            • seekp() is used to move the put pointer to a desired location with respect to a reference point.


            • tellp() is used to know where the put pointer is in a file.





            Main source: Quora, answer by Gunjan B. Yadav on Dec 1, 2017.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Dec 4 at 14:27









            Rakete1111

            34k980116




            34k980116










            answered Dec 4 at 8:32









            Tu.ma

            804218




            804218








            • 12




              Why do C++ standards people name APIs as if keyboards have per-keystroke costs. 🙄
              – Alexander
              Dec 5 at 0:33








            • 10




              @Alexander : to avoid people getting paid by keystroke, obviously. Clever and business-oriented programmers naturally overcome this problem by inventing their own types and wrappers for the standard library, which of course always works out perfectly and has no disadvantages whatsoever.
              – Daniel Kamil Kozar
              Dec 5 at 0:35










            • @DanielKamilKozar Haha, I had a good chuckle.
              – Alexander
              Dec 5 at 0:39










            • @Alexander en.cppreference.com/w/cpp/chrono/high_resolution_clock
              – Ajay
              Dec 5 at 7:09












            • @Ajay I like it!
              – Alexander
              Dec 5 at 18:41














            • 12




              Why do C++ standards people name APIs as if keyboards have per-keystroke costs. 🙄
              – Alexander
              Dec 5 at 0:33








            • 10




              @Alexander : to avoid people getting paid by keystroke, obviously. Clever and business-oriented programmers naturally overcome this problem by inventing their own types and wrappers for the standard library, which of course always works out perfectly and has no disadvantages whatsoever.
              – Daniel Kamil Kozar
              Dec 5 at 0:35










            • @DanielKamilKozar Haha, I had a good chuckle.
              – Alexander
              Dec 5 at 0:39










            • @Alexander en.cppreference.com/w/cpp/chrono/high_resolution_clock
              – Ajay
              Dec 5 at 7:09












            • @Ajay I like it!
              – Alexander
              Dec 5 at 18:41








            12




            12




            Why do C++ standards people name APIs as if keyboards have per-keystroke costs. 🙄
            – Alexander
            Dec 5 at 0:33






            Why do C++ standards people name APIs as if keyboards have per-keystroke costs. 🙄
            – Alexander
            Dec 5 at 0:33






            10




            10




            @Alexander : to avoid people getting paid by keystroke, obviously. Clever and business-oriented programmers naturally overcome this problem by inventing their own types and wrappers for the standard library, which of course always works out perfectly and has no disadvantages whatsoever.
            – Daniel Kamil Kozar
            Dec 5 at 0:35




            @Alexander : to avoid people getting paid by keystroke, obviously. Clever and business-oriented programmers naturally overcome this problem by inventing their own types and wrappers for the standard library, which of course always works out perfectly and has no disadvantages whatsoever.
            – Daniel Kamil Kozar
            Dec 5 at 0:35












            @DanielKamilKozar Haha, I had a good chuckle.
            – Alexander
            Dec 5 at 0:39




            @DanielKamilKozar Haha, I had a good chuckle.
            – Alexander
            Dec 5 at 0:39












            @Alexander en.cppreference.com/w/cpp/chrono/high_resolution_clock
            – Ajay
            Dec 5 at 7:09






            @Alexander en.cppreference.com/w/cpp/chrono/high_resolution_clock
            – Ajay
            Dec 5 at 7:09














            @Ajay I like it!
            – Alexander
            Dec 5 at 18:41




            @Ajay I like it!
            – Alexander
            Dec 5 at 18:41


















            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53608590%2fwhat-does-the-g-stand-for-in-gcount-tellg-and-seekg%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            How to change which sound is reproduced for terminal bell?

            Can I use Tabulator js library in my java Spring + Thymeleaf project?

            Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents