-1
A
回答
0
你可以嘗試這樣的事情:
#include <iostream>
#include <iterator>
#include <string>
int main()
{
std::istream_iterator<std::string> it(std::cin);
std::istream_iterator<std::string> end_it;
std::string str;
for (int i = 0; i < 3; ++i)
if (it != end_it) {
str += *it;
if (i != 2)
++it;
} else {
break;
}
std::cout << "Res: " << str << "\n";
}
而且更易於使用只有兩個std::string
變量, 一個用於電流輸入,另一個用於積累。
相關問題
- 1. C++追加到字符串
- 2. C字符串追加
- 3. C字符串追加
- 4. 追加字符數組字符串C++
- 5. 追加到字符串?
- 6. CON-CAT /追加字符串流用C
- 7. 追加XML字符串到現有XMLFILE使用C#
- 8. 追加字符串
- 9. 追加字符串
- 10. C++字符串數組追加目標C++崩潰追加
- 11. 如何使用sprintf追加字符串?
- 12. 使用StringBuilder追加字符串
- 13. 用隨機字符串追加AJAX請求追加到URL
- 14. 追加字符串,Objective-C的
- 15. 目標c追加字符串cocos2d
- 16. 在C中追加字符串
- 17. C++追加字符串指針
- 18. 用cin讀取字符(C++)
- 19. 追加字符串字符串
- 20. C++ cout cin字符串操作
- 21. C++:在字符串中追加語義#追加
- 22. 將字符串追加到UILabel文本?
- 23. 追加字符串到StringBuffer,給NullPointerException
- 24. 追加到字符串名稱
- 25. 追加到字符串蟒蛇
- 26. 高效追加到字符串(Golang)
- 27. 追加到getJSON中的字符串
- 28. 追加到字符串的末尾Ramda.js
- 29. 追加查詢字符串到url
- 30. LINQ從字符串追加到StringBuilder []
爲什麼你不能只是'cin'到一個不同的字符串,然後使用'std :: string :: operator +'將這些字符串追加到一起呢? –