Compare string and stringstrean | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Compare string and stringstrean

String s = "abcd1234"; Stringstream ss; ss<<"abcd"; ss<<"1234"; If(s==ss) Cout<<"yes"; Else Cout<<"no"; And answer is no. But why? What and how are they compares? Because if i compare with "for" loop char by char all is okay.

10th Mar 2019, 8:44 AM
Otakoe
Otakoe - avatar
1 Answer
+ 10
It should return true for equality checking i edited your code, #include <iostream> #include <sstream> using namespace std; int main() { string s = "abcd1234"; string s2; stringstream ss; ss<<"abcd"; ss<<"1234"; ss>>s2; if(s==s2){ cout<<"yes";} else{ cout<<"no";} return 0; }
10th Mar 2019, 9:52 AM
D_Stark
D_Stark - avatar