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 は次のように切り捨てられます。

「ザ・クイック・ブラウン・フォックス・ジャンプ・オーバー・ザ・レイジー・ドッグ」は英語のパングラム(

サイズ制限はどこで設定できますか? 私は成功せずに次のことを試しました:

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

(2番目の)アサーションは失敗しますか?

于 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

テキストを印刷または表示するとき、出力機構は出力をバッファリングします。'\n' を出力するか、次のメソッドを使用std::endlまたは実行することで、バッファをフラッシュする (残りのすべてのテキストを表示する) ように指示できます。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 に答える