-1

当字符串小于 15 个字节时,sendbyts 打印所有值。我用 strtok 验证了内容,所有详细信息都存在于字符串中。我无法用 cout< 输出整个字符串

 for(i=0;i<=1;i++){
             sendbyts= peerinfo[i].n_ip;
             sendbyts.append(" ");
             cout<< peerinfo[i].n_ip<<"\n";  
            //verify whether the right data is appended                  
             sendbyts.append(peerinfo[i].n_portno);
             sendbyts.append(" ");
             cout<< peerinfo[i].n_portno<<"\n";
             cout<<"verify the string here :"<<sendbyts<<"\n";
             sendbyts.append("0x0");
             sendbyts.append(" ");
             cout<<" \n verify the string again :"<<sendbyts<<"\n";
             sendbyts.append(peerinfo[i].n_sno);
             sendbyts.append(" ");
             cout<<peerinfo[i].n_sno<<"\n";
             sendbyts.append("|");
             cout<<" \n final verification  :"<<sendbyts<<"\n";
     }
     cout<<"final string formed  "<<sendbyts<<"\n";

     output
     128.205.36.8
     6666
     erify the string here :128.205.36.8 6666
     0x0 fy the string again :128.205.36.8 6666
     0x0 1 |erification  128.205.36.8 6666

     Expected output
     128.205.36.8
     6666
     verify the string here :128.205.36.8 6666128.205.36.8 6666
     verify the string again :128.205.36.8 6666 0x0
     final verification :128.205.36.8 6666 0x0 1|
4

1 回答 1

1

您的输出看起来像是在打印没有换行符的回车符 ('\r')。发生这种情况时,光标会回到行首而不向下移动。后续文本打印在最后一个文本之上。

尝试将任何 '\r' 字符更改为 '\n' 字符。

于 2013-10-29T15:47:46.920 回答