0
int x;
float f;
std::string s = "3.7";
std::istringstream is(s);
is >> x >> f;
なぜ 'x'と 'f'の結果は3と0.7ですか?
私はstd :: istringstreamの結果を理解する方法は?
is >> f;
'F' の結果を使用し3.7です。
int x;
float f;
std::string s = "3.7";
std::istringstream is(s);
is >> x >> f;
なぜ 'x'と 'f'の結果は3と0.7ですか?
私はstd :: istringstreamの結果を理解する方法は?
is >> f;
'F' の結果を使用し3.7です。
istreamstreamは、ストリームから多くの文字を抽出し、fit into the target datatype(算術型を参照)と同じように抽出します。もう1つの停止条件はスペース文字です。
ですから、次のようにコードを変更するかどう:
int x;
char c;
int f;
std::string s = "3.7";
std::istringstream is(s);
is >> x;
is >> c;
is >> f;
std::cout << x << std::endl;
std::cout << c << std::endl;
std::cout << f << std::endl;
これは、次の出力のような結果になります。(」7" )を
3
.
7
私の答えがあなたを助けてくれたら、それを正しい答えとするのがいいでしょう。 –
'のstd :: istringstreamがあります。 >> f; ' –