1

我初始化一个字符串如下:

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 最终像这样被切断:

'The quick brown fox jumps over the lazy dog' 是一个英语 pangram(一个短语包含

我在哪里可以设置大小限制?我尝试了以下但没有成功:

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)";

非常感谢!

4

4 回答 4

1

当然,这只是调试器将其切断(xcode)。我刚刚开始使用 xcode/c++,非常感谢您的快速回复。

于 2011-11-05T15:38:57.027 回答
0

尝试以下操作(在调试模式下):

assert(!"Congratulations, I am in debug mode! Let's do a test now...")
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)";
assert(myString.size() > 120);

(第二个)断言是否失败?

于 2010-09-15T12:28:54.820 回答
0

你确定吗?

kkekan> ./a.out 
'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)

没有充分的理由为什么会发生这种情况!

于 2010-09-15T12:51:24.910 回答
0

打印或显示文本时,输出机器会缓冲输出。std::endl您可以通过输出 '\n' 或使用或执行该flush()方法来告诉它刷新缓冲区(显示所有剩余文本) :

#include <iostream>
using std::cout;
using std::endl;

int main(void)
{
  std::string myString =
    "'The quick brown fox jumps over the lazy dog'" // Compiler concatenates
    " is an English-language pangram (a phrase"     // these contiguous text
    " that contains all of the letters of the"      // literals automatically.
    " alphabet)";
  // Method 1:  use '\n'
  // A newline forces the buffers to flush.
  cout << myString << '\n';

  // Method 2:  use std::endl;
  // The std::endl flushes the buffer then sends '\n' to the output.
  cout << myString << endl;

  // Method 3:  use flush() method
  cout << myString;
  cout.flush();

  return 0;
}

有关缓冲区的更多信息,请在堆栈溢出中搜索“C++ 输出缓冲区”。

于 2010-09-15T19:13:29.127 回答