为什么我的 std::string 被切断?
我按如下方式初始化一个字符串:
std::string myString = "'The quick brown fox jumps over the lazy dog' is an English-language pangram (a phrase that contains all of the letters of the alphabet)";
myString 最终被这样切断:
'敏捷的棕色狐狸跳过了 “懒狗”是英语 pangram(包含的短语
pangram(包含Where can i set the size limit? ) 我尝试了以下方法但没有成功:
std::string myString;
myString.resize(300);
myString = "'The quick brown fox jumps over the lazy dog' is an English-language pangram (a phrase that contains all of the letters of the alphabet)";
非常感谢!
I initialize a string as follows:
std::string myString = "'The quick brown fox jumps over the lazy dog' is an English-language pangram (a phrase that contains all of the letters of the alphabet)";
and the myString ends up being cut off like this:
'The quick brown fox jumps over the
lazy dog' is an English-language
pangram (a phrase that contains
Where can i set the size limit?
I tried the following without success:
std::string myString;
myString.resize(300);
myString = "'The quick brown fox jumps over the lazy dog' is an English-language pangram (a phrase that contains all of the letters of the alphabet)";
Many thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
当然,这只是调试器将其切断(xcode)。我刚刚开始使用 xcode/c++,所以非常感谢您的快速回复。
Of course it was just the debugger cutting it off (xcode). I'm just getting started with xcode/c++, so thanks a lot for the quick replies.
你确定吗?
没有充分的理由为什么会发生这种情况!
Are you sure?
There is no good reason why this should have happen!
尝试以下操作(在调试模式下):(
第二个)断言是否失败?
Try the following (in debug mode):
Does the (second) assertion fail?
打印或显示文本时,输出机器会缓冲输出。 告诉它刷新缓冲区(显示所有剩余文本):
您可以通过输出 '\n' 或使用
std::endl
或执行flush()
方法来 有关缓冲区的更多信息,请在 Stack Overflow 中搜索“C++ 输出缓冲区”。When printing, or displaying text, the output machinery buffers the output. You can tell it to flush the buffers (display all remaining text) by output a '\n' or using
std::endl
or executing theflush()
method:For more information about buffers, search Stack Overflow for "C++ output buffer".