只能在字符串中添加一定数量的字符-C ++

时间:2018-10-31 23:28:50

标签: c++ string character

我正在用C ++创建一个套接字应用程序,在这里我必须解码base64字符串。我正在使用RenéNyffenegger(https://renenyffenegger.ch/notes/development/Base64/Encoding-and-decoding-base-64-with-cpp)的代码来执行此操作。我发现的animations: [ trigger('slideInOut', [ state('slideIn', style({ webkitMaskPosition: "0 0" })), state('slideOut', style({ webkitMaskPosition: "100% 0" })), transition('slideIn => slideOut', [ animate('2s', keyframes([ style({webkitMaskPosition: '0 0'}), style({webkitMaskPosition: "100% 0"}) ])) ]), transition('slideOut => slideIn', [ animate('2s', keyframes([ style({webkitMaskPosition: "100% 0"}), style({webkitMaskPosition: "0 0"}) ])) ]), ]), ], 函数中的ret字符串总是只有4个字符长,花了一些时间调试之后,我才意识到这全都归结为:

base64_decode

由于某种原因,此代码仅向unsigned char1 = 255; unsigned char2 = 216; unsigned char3 = 255; unsigned char4 = 224; unsigned char5 = 0; unsigned char6 = 16; unsigned char7 = 74; unsigned char8 = 70; unsigned char9 = 73; string str; str += char1; str += char2; str += char3; str += char4; str += char5; str += char6; str += char7; str += char8; str += char9; 添加char1char2char3char4,其余字符完全被忽略。为什么会这样,我该怎么解决?

1 个答案:

答案 0 :(得分:0)

问题可能是char5中的0吗? C字符串以null终止,因此,如果您将字符串强制转换为C字符串,我想它会在那时被截断。

再次请注意,这是C问题,而不是C ++问题,但是在您的情况下,可能会发生这种转换。