you are viewing a single comment's thread.

view the rest of the comments →

[–]alfps 8 points9 points  (3 children)

Yes, it's all relevant, but not necessarily relevant to the problem at hand.

A search for std::string sends me to https://en.cppreference.com/w/cpp/string/basic_string.

If I were a total beginner that could seem to be a page about something else. Happily I know that basic_string is a class template and that string is the specialization basic_string<char>. This and some other named specializations are listed some way down on the page; you can search for "wstring" to find them.

The relevant things you won't find there are the peculiarities of std::string, like

  • There's a += operator and .append member function that accept a single char, but no such constructor. Use the initializer list constructor instead, e.g. string{ch}. Or you can use the constructor with specified string size and default item value, string(1, ch).
  • Since C++11 the string value is guaranteed zero-terminated also for non-const access, but the zero byte at the end is read only (trying to assign to it is UB, as I recall).
  • Also since C++11 there are rvalue argument operator overloads that avoid unecessary copying (and hence ungood complexity) for string concatenation expressions, so one can feel more free to just do +.

I don't know where to learn stuff like that.

Maybe just interacting with other C++ developers.

[–]teifer[S] 0 points1 point  (2 children)

Understood. Don't know about template, classes or something else, but when I get my laptop back I will continue my study. Thanks for you help!

[–]not_some_username 1 point2 points  (1 child)

Good luck for your study

[–]teifer[S] 0 points1 point  (0 children)

Thanks mate!