There is a string

char buff[1024]; //1024 bsize = 3 // зависит от строки 

Receives data, add 0 to the end of the line

 // добавление завершающего нуля buff[bsize] = 0; 

Translate string to string

 string name = buff; // результат "hi" 

There is one more string

 String test = "hi"; 

The question arises why the result is false? If it should be true

 if(name == test) // Результат false 
  • What is the magic number bsize ? - 0xdb
  • Everything works. Try, except that '\0' instead of 0 . Or you have a newline in buf gets. - andy.37
  • andy added. But it did not help. Although when I output a string to the console, the value is indeterminate - user248223
  • and maybe String and string are different classes? then everything can be. - KoVadim
  • 2
    @ Ewrei_228 Of course, that’s the point. Print the ASCII character codes in the name and see what you have there too much. for (char x : name) cout << int(x) << endl; - andy.37

1 answer 1

Most likely, non-printable characters (of type \n , \r ) fall into the name string. Check the equality of the row sizes ( name.size() == test.size() ) and if they do not match, output the character codes in the name string:

 for (char x : name) cout << int(x) << endl;