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











up vote
-1
down vote

favorite












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 at 8:40












  • What is key ?
    – tkausl
    Nov 17 at 8:41










  • @Mazhar c_str() return const char *.
    – lxc
    Nov 17 at 8:42






  • 1




    @Mazhar c_str() is C++. I've retagged the question. To the OP: Please use relevant tags only
    – Cool Guy
    Nov 17 at 10:41








  • 1




    @Mazhar I have solve it by myself. Happy.
    – lxc
    Nov 17 at 13:03















up vote
-1
down vote

favorite












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 at 8:40












  • What is key ?
    – tkausl
    Nov 17 at 8:41










  • @Mazhar c_str() return const char *.
    – lxc
    Nov 17 at 8:42






  • 1




    @Mazhar c_str() is C++. I've retagged the question. To the OP: Please use relevant tags only
    – Cool Guy
    Nov 17 at 10:41








  • 1




    @Mazhar I have solve it by myself. Happy.
    – lxc
    Nov 17 at 13:03













up vote
-1
down vote

favorite









up vote
-1
down vote

favorite











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 at 10:40









Cool Guy

17.3k62560




17.3k62560










asked Nov 17 at 8:38









lxc

217




217












  • 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 at 8:40












  • What is key ?
    – tkausl
    Nov 17 at 8:41










  • @Mazhar c_str() return const char *.
    – lxc
    Nov 17 at 8:42






  • 1




    @Mazhar c_str() is C++. I've retagged the question. To the OP: Please use relevant tags only
    – Cool Guy
    Nov 17 at 10:41








  • 1




    @Mazhar I have solve it by myself. Happy.
    – lxc
    Nov 17 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 at 8:40












  • What is key ?
    – tkausl
    Nov 17 at 8:41










  • @Mazhar c_str() return const char *.
    – lxc
    Nov 17 at 8:42






  • 1




    @Mazhar c_str() is C++. I've retagged the question. To the OP: Please use relevant tags only
    – Cool Guy
    Nov 17 at 10:41








  • 1




    @Mazhar I have solve it by myself. Happy.
    – lxc
    Nov 17 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 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 at 8:40














What is key ?
– tkausl
Nov 17 at 8:41




What is key ?
– tkausl
Nov 17 at 8:41












@Mazhar c_str() return const char *.
– lxc
Nov 17 at 8:42




@Mazhar c_str() return const char *.
– lxc
Nov 17 at 8:42




1




1




@Mazhar c_str() is C++. I've retagged the question. To the OP: Please use relevant tags only
– Cool Guy
Nov 17 at 10:41






@Mazhar c_str() is C++. I've retagged the question. To the OP: Please use relevant tags only
– Cool Guy
Nov 17 at 10:41






1




1




@Mazhar I have solve it by myself. Happy.
– lxc
Nov 17 at 13:03




@Mazhar I have solve it by myself. Happy.
– lxc
Nov 17 at 13:03












2 Answers
2






active

oldest

votes

















up vote
2
down vote



accepted










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
    2 days ago


















up vote
0
down vote













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',
    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








    up vote
    2
    down vote



    accepted










    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
      2 days ago















    up vote
    2
    down vote



    accepted










    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
      2 days ago













    up vote
    2
    down vote



    accepted







    up vote
    2
    down vote



    accepted






    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 at 18:09

























    answered Nov 17 at 16:19









    Tom Blodget

    15.8k22450




    15.8k22450












    • Thank you. I know the reason behind the phenomenon.
      – lxc
      2 days ago


















    • Thank you. I know the reason behind the phenomenon.
      – lxc
      2 days ago
















    Thank you. I know the reason behind the phenomenon.
    – lxc
    2 days ago




    Thank you. I know the reason behind the phenomenon.
    – lxc
    2 days ago












    up vote
    0
    down vote













    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



























      up vote
      0
      down vote













      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

























        up vote
        0
        down vote










        up vote
        0
        down vote









        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 2 days ago

























        answered Nov 17 at 13:00









        lxc

        217




        217






























             

            draft saved


            draft discarded



















































             


            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

            If I really need a card on my start hand, how many mulligans make sense? [duplicate]

            Alcedinidae

            Can an atomic nucleus contain both particles and antiparticles? [duplicate]