![](/img/trans.png)
[英]How to Generically Define Insertion Operators for all C++ IOStream Manipulators?
[英]Chaining iostream operators in c++
#include <iostream>
#include <string>
using namespace std;
int main()
{
string w;
cin >> w;
w += " World";
cout << cout << ' ' << cin << ' ' << w << endl;
};
當“hola”是用戶輸入時產生的 output:
hola
1 1 hola world
為什么第一線生產hola
? 我知道第二行是成功cout
, cin
和連接字符串的結果。
這是你如何做到的:
#include <string>
#include <iostream>
int main()
{
std::string w;
std::cin >> w;
std::cout << w << " world\n";
}
閱讀和打印是兩個獨立的步驟,您不要將它們鏈接起來。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.