teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

C\+\+11なら・・・

2016/05/08 15:06

投稿

raccy
raccy

スコア21767

answer CHANGED
@@ -14,4 +14,24 @@
14
14
  }
15
15
  targetStr = destStr;
16
16
  }
17
+ ```
18
+
19
+ ---
20
+ おまけ
21
+
22
+ C++11が使えるならムーブにすることで、ちょっとだけ速くなるような気がします。
23
+
24
+ ```C++
25
+ void deleteNl2(std::string &targetStr)
26
+ {
27
+ const char CR = '\r';
28
+ const char LF = '\n';
29
+ std::string destStr;
30
+ for (const auto c : targetStr) {
31
+ if (c != CR && c != LF) {
32
+ destStr += c;
33
+ }
34
+ }
35
+ targetStr = std::move(destStr);
36
+ }
17
37
  ```