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?
c++ character ascii
|
show 8 more comments
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?
c++ character ascii
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 iskey
?
– tkausl
Nov 17 at 8:41
@Mazhar c_str() return const char *.
– lxc
Nov 17 at 8:42
1
@Mazharc_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
|
show 8 more comments
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?
c++ character ascii
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
c++ character ascii
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 iskey
?
– tkausl
Nov 17 at 8:41
@Mazhar c_str() return const char *.
– lxc
Nov 17 at 8:42
1
@Mazharc_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
|
show 8 more comments
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 iskey
?
– tkausl
Nov 17 at 8:41
@Mazhar c_str() return const char *.
– lxc
Nov 17 at 8:42
1
@Mazharc_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
|
show 8 more comments
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).
Thank you. I know the reason behind the phenomenon.
– lxc
2 days ago
add a comment |
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";
add a comment |
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).
Thank you. I know the reason behind the phenomenon.
– lxc
2 days ago
add a comment |
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).
Thank you. I know the reason behind the phenomenon.
– lxc
2 days ago
add a comment |
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).
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).
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
add a comment |
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
add a comment |
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";
add a comment |
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";
add a comment |
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";
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";
edited 2 days ago
answered Nov 17 at 13:00
lxc
217
217
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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