且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在此输出中的每四个字符之间放置一个空格?

更新时间:2023-02-04 23:10:01

您已经有了一个计数器,因此您可以使用它来确定正在使用哪个字符.例如:

You already have a counter going, so you can just use that to determine which character you're on. For example:

if(count == 3){

    cout << " ";
}

只需在if-else语句之前添加此if.这样,一旦您输出了4个字符,count将为3,因此您知道必须输出一个空格.

Just add this if before your if-else statement. That way, once you have outputted 4 characters, count will be 3, so you know you have to output a space.

注意:这是假设您一次只能输出8个字符,如代码所示.

Note: this is assuming you're only ever outputting 8 characters at a time, as your code suggests.