what's exactly the string of “^A” is?












-1















I run my code on an online judgement. I log the string, key. Below is my code:



fprintf(stderr, "key=%s, and key.size()=%dn", key.c_str(), key.size());


But the result is this:



key=^A, and key.size()=8


I want to what is the ^A represent in ascii. ^A's size is 2 rather than 8, but it shows that it is 8. I view the result by vim, and the log_file is encoded by UTF-8. Why?










share|improve this question

























  • What value the c_str() is returning actually ? Share the structure Key, and the values you are storing to it's data members.

    – Mazhar
    Nov 17 '18 at 8:40













  • What is key ?

    – tkausl
    Nov 17 '18 at 8:41











  • @Mazhar c_str() return const char *.

    – lxc
    Nov 17 '18 at 8:42






  • 1





    @Mazhar c_str() is C++. I've retagged the question. To the OP: Please use relevant tags only

    – Spikatrix
    Nov 17 '18 at 10:41








  • 1





    @Mazhar I have solve it by myself. Happy.

    – lxc
    Nov 17 '18 at 13:03
















-1















I run my code on an online judgement. I log the string, key. Below is my code:



fprintf(stderr, "key=%s, and key.size()=%dn", key.c_str(), key.size());


But the result is this:



key=^A, and key.size()=8


I want to what is the ^A represent in ascii. ^A's size is 2 rather than 8, but it shows that it is 8. I view the result by vim, and the log_file is encoded by UTF-8. Why?










share|improve this question

























  • What value the c_str() is returning actually ? Share the structure Key, and the values you are storing to it's data members.

    – Mazhar
    Nov 17 '18 at 8:40













  • What is key ?

    – tkausl
    Nov 17 '18 at 8:41











  • @Mazhar c_str() return const char *.

    – lxc
    Nov 17 '18 at 8:42






  • 1





    @Mazhar c_str() is C++. I've retagged the question. To the OP: Please use relevant tags only

    – Spikatrix
    Nov 17 '18 at 10:41








  • 1





    @Mazhar I have solve it by myself. Happy.

    – lxc
    Nov 17 '18 at 13:03














-1












-1








-1








I run my code on an online judgement. I log the string, key. Below is my code:



fprintf(stderr, "key=%s, and key.size()=%dn", key.c_str(), key.size());


But the result is this:



key=^A, and key.size()=8


I want to what is the ^A represent in ascii. ^A's size is 2 rather than 8, but it shows that it is 8. I view the result by vim, and the log_file is encoded by UTF-8. Why?










share|improve this question
















I run my code on an online judgement. I log the string, key. Below is my code:



fprintf(stderr, "key=%s, and key.size()=%dn", key.c_str(), key.size());


But the result is this:



key=^A, and key.size()=8


I want to what is the ^A represent in ascii. ^A's size is 2 rather than 8, but it shows that it is 8. I view the result by vim, and the log_file is encoded by UTF-8. Why?







c++ character ascii






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 17 '18 at 10:40









Spikatrix

17.4k62660




17.4k62660










asked Nov 17 '18 at 8:38









lxclxc

218




218













  • What value the c_str() is returning actually ? Share the structure Key, and the values you are storing to it's data members.

    – Mazhar
    Nov 17 '18 at 8:40













  • What is key ?

    – tkausl
    Nov 17 '18 at 8:41











  • @Mazhar c_str() return const char *.

    – lxc
    Nov 17 '18 at 8:42






  • 1





    @Mazhar c_str() is C++. I've retagged the question. To the OP: Please use relevant tags only

    – Spikatrix
    Nov 17 '18 at 10:41








  • 1





    @Mazhar I have solve it by myself. Happy.

    – lxc
    Nov 17 '18 at 13:03



















  • What value the c_str() is returning actually ? Share the structure Key, and the values you are storing to it's data members.

    – Mazhar
    Nov 17 '18 at 8:40













  • What is key ?

    – tkausl
    Nov 17 '18 at 8:41











  • @Mazhar c_str() return const char *.

    – lxc
    Nov 17 '18 at 8:42






  • 1





    @Mazhar c_str() is C++. I've retagged the question. To the OP: Please use relevant tags only

    – Spikatrix
    Nov 17 '18 at 10:41








  • 1





    @Mazhar I have solve it by myself. Happy.

    – lxc
    Nov 17 '18 at 13:03

















What value the c_str() is returning actually ? Share the structure Key, and the values you are storing to it's data members.

– Mazhar
Nov 17 '18 at 8:40







What value the c_str() is returning actually ? Share the structure Key, and the values you are storing to it's data members.

– Mazhar
Nov 17 '18 at 8:40















What is key ?

– tkausl
Nov 17 '18 at 8:41





What is key ?

– tkausl
Nov 17 '18 at 8:41













@Mazhar c_str() return const char *.

– lxc
Nov 17 '18 at 8:42





@Mazhar c_str() return const char *.

– lxc
Nov 17 '18 at 8:42




1




1





@Mazhar c_str() is C++. I've retagged the question. To the OP: Please use relevant tags only

– Spikatrix
Nov 17 '18 at 10:41







@Mazhar c_str() is C++. I've retagged the question. To the OP: Please use relevant tags only

– Spikatrix
Nov 17 '18 at 10:41






1




1





@Mazhar I have solve it by myself. Happy.

– lxc
Nov 17 '18 at 13:03





@Mazhar I have solve it by myself. Happy.

– lxc
Nov 17 '18 at 13:03












2 Answers
2






active

oldest

votes


















2














Your viewer is electing to show you the bytes interpreted using a character encoding of its choosing and electing to show the resulting characters in caret notation.



Other viewers could make different choices on both counts or allow you to indicate what you want. For example, control picture characters (␁) instead of caret notation.



For a std:string c_str() is terminated by an additional x00 byte following the actual value. You often use c_str() with functions that expect a string to be x00 terminated. This applies to fprintf. In such cases, what's read ends just before the first x00 seen.



You have several x00 bytes in your string, which, of course, contributes to size() but fprintf will stop right at the first one (and not count it).






share|improve this answer


























  • Thank you. I know the reason behind the phenomenon.

    – lxc
    Nov 18 '18 at 7:49



















0














I have solve it by myself. If you write a std::string "x01x00x00x00x00end" to a file and open it with vim later, you will get '^A'.



This is my test code:



string sss("x01x00x00x00x00end");
ofstream of("of.txt");
for (int i=0; i<sss.size(); i++) {
of.put(sss[i]);
}

of.close();


After I open the file "of.txt", I saw "^A";






share|improve this answer

























    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',
    autoActivateHeartbeat: false,
    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%2f53349606%2fwhats-exactly-the-string-of-a-is%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









    2














    Your viewer is electing to show you the bytes interpreted using a character encoding of its choosing and electing to show the resulting characters in caret notation.



    Other viewers could make different choices on both counts or allow you to indicate what you want. For example, control picture characters (␁) instead of caret notation.



    For a std:string c_str() is terminated by an additional x00 byte following the actual value. You often use c_str() with functions that expect a string to be x00 terminated. This applies to fprintf. In such cases, what's read ends just before the first x00 seen.



    You have several x00 bytes in your string, which, of course, contributes to size() but fprintf will stop right at the first one (and not count it).






    share|improve this answer


























    • Thank you. I know the reason behind the phenomenon.

      – lxc
      Nov 18 '18 at 7:49
















    2














    Your viewer is electing to show you the bytes interpreted using a character encoding of its choosing and electing to show the resulting characters in caret notation.



    Other viewers could make different choices on both counts or allow you to indicate what you want. For example, control picture characters (␁) instead of caret notation.



    For a std:string c_str() is terminated by an additional x00 byte following the actual value. You often use c_str() with functions that expect a string to be x00 terminated. This applies to fprintf. In such cases, what's read ends just before the first x00 seen.



    You have several x00 bytes in your string, which, of course, contributes to size() but fprintf will stop right at the first one (and not count it).






    share|improve this answer


























    • Thank you. I know the reason behind the phenomenon.

      – lxc
      Nov 18 '18 at 7:49














    2












    2








    2







    Your viewer is electing to show you the bytes interpreted using a character encoding of its choosing and electing to show the resulting characters in caret notation.



    Other viewers could make different choices on both counts or allow you to indicate what you want. For example, control picture characters (␁) instead of caret notation.



    For a std:string c_str() is terminated by an additional x00 byte following the actual value. You often use c_str() with functions that expect a string to be x00 terminated. This applies to fprintf. In such cases, what's read ends just before the first x00 seen.



    You have several x00 bytes in your string, which, of course, contributes to size() but fprintf will stop right at the first one (and not count it).






    share|improve this answer















    Your viewer is electing to show you the bytes interpreted using a character encoding of its choosing and electing to show the resulting characters in caret notation.



    Other viewers could make different choices on both counts or allow you to indicate what you want. For example, control picture characters (␁) instead of caret notation.



    For a std:string c_str() is terminated by an additional x00 byte following the actual value. You often use c_str() with functions that expect a string to be x00 terminated. This applies to fprintf. In such cases, what's read ends just before the first x00 seen.



    You have several x00 bytes in your string, which, of course, contributes to size() but fprintf will stop right at the first one (and not count it).







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Nov 17 '18 at 18:09

























    answered Nov 17 '18 at 16:19









    Tom BlodgetTom Blodget

    16.1k22452




    16.1k22452













    • Thank you. I know the reason behind the phenomenon.

      – lxc
      Nov 18 '18 at 7:49



















    • Thank you. I know the reason behind the phenomenon.

      – lxc
      Nov 18 '18 at 7:49

















    Thank you. I know the reason behind the phenomenon.

    – lxc
    Nov 18 '18 at 7:49





    Thank you. I know the reason behind the phenomenon.

    – lxc
    Nov 18 '18 at 7:49













    0














    I have solve it by myself. If you write a std::string "x01x00x00x00x00end" to a file and open it with vim later, you will get '^A'.



    This is my test code:



    string sss("x01x00x00x00x00end");
    ofstream of("of.txt");
    for (int i=0; i<sss.size(); i++) {
    of.put(sss[i]);
    }

    of.close();


    After I open the file "of.txt", I saw "^A";






    share|improve this answer






























      0














      I have solve it by myself. If you write a std::string "x01x00x00x00x00end" to a file and open it with vim later, you will get '^A'.



      This is my test code:



      string sss("x01x00x00x00x00end");
      ofstream of("of.txt");
      for (int i=0; i<sss.size(); i++) {
      of.put(sss[i]);
      }

      of.close();


      After I open the file "of.txt", I saw "^A";






      share|improve this answer




























        0












        0








        0







        I have solve it by myself. If you write a std::string "x01x00x00x00x00end" to a file and open it with vim later, you will get '^A'.



        This is my test code:



        string sss("x01x00x00x00x00end");
        ofstream of("of.txt");
        for (int i=0; i<sss.size(); i++) {
        of.put(sss[i]);
        }

        of.close();


        After I open the file "of.txt", I saw "^A";






        share|improve this answer















        I have solve it by myself. If you write a std::string "x01x00x00x00x00end" to a file and open it with vim later, you will get '^A'.



        This is my test code:



        string sss("x01x00x00x00x00end");
        ofstream of("of.txt");
        for (int i=0; i<sss.size(); i++) {
        of.put(sss[i]);
        }

        of.close();


        After I open the file "of.txt", I saw "^A";







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 18 '18 at 7:47

























        answered Nov 17 '18 at 13:00









        lxclxc

        218




        218






























            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.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53349606%2fwhats-exactly-the-string-of-a-is%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 pass form data using jquery Ajax to insert data in database?

            National Museum of Racing and Hall of Fame

            Guess what letter conforming each word