在g +++中无法打印大字符串

时间:2013-10-29 15:06:40

标签: c++

当字符串小于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|

1 个答案:

答案 0 :(得分:1)

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

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