stdstring

Reading a specific number of characters from C++ stream into std::string

痴心易碎 提交于 2021-01-27 04:56:17
问题 I'm pretty familiar with most of C++ but one area I've avoided has been IO streams, mainly because I've been using it on embedded systems where they're not appropriate. Recently I've had to become familiar with them, however, and I'm struggling to figure out something that I feel should be simple. What I'm looking for a relatively efficient way to read a fixed number of characters from a C++ stream into a std::string . I could easily read into a temporary char array with the read() method and

Converting QString to std::string

瘦欲@ 提交于 2021-01-27 04:37:09
问题 I've seen several other posts about converting QString to std::string, and it should be simple. But somehow I'm getting an error. My code is compiled into a VS project using cmake (I'm using VS express), so there's no issue with the QT libraries, and the GUI that I wrote works besides this part. I have a QComboBox cb that holds the names to some objects, and a QLineEdit lineEdit that allows me to specify the name of the object that I am looking for. It should run a function that is tested and

2d char vector printing spaces when printing second column

故事扮演 提交于 2020-07-22 06:00:10
问题 Here I have a 2d vector of char - std::vector<std::vector<char>> solution = { {"O","1"}, {"T","0"}, {"W","9"}, {"E","5"}, {"N","4"} }; Printing anything from first column - prints fine. cout << "In main - " << solution [ 1 ] [ 0 ]; // Prints T But when I try to access element of second column. cout << "In main - " << solution [ 1 ] [ 1 ]; // Prints blank space - I can't seem to understand why's the case. After quiet amount of searching I tried by putting single quotes around every element.

Length of a C++ std::string in bytes

折月煮酒 提交于 2020-07-18 08:56:47
问题 I'm having some trouble figuring out the exact semantics of std::string.length() . The documentation explicitly points out that length() returns the number of characters in the string and not the number of bytes. I was wondering in which cases this actually makes a difference. In particular, is this only relevant to non-char instantiations of std::basic_string<> or can I also get into trouble when storing UTF-8 strings with multi-byte characters? Does the standard allow for length() to be

Will std::string end up being our compile-time string after all?

∥☆過路亽.° 提交于 2020-07-15 04:14:29
问题 Many developers and library authors have been struggling with compile-time strings for quite a few years now - as the standard (library) string, std::string , requires dynamic memory allocation, and isn't constexpr. So we have a bunch of questions and blog posts about how to get compile-time strings right: Conveniently Declaring Compile-Time Strings in C++ Concatenate compile-time strings in a template at compile time? C++ Compile-Time string manipulation (off-site) Compile-time strings with

Will std::string end up being our compile-time string after all?

丶灬走出姿态 提交于 2020-07-15 04:14:29
问题 Many developers and library authors have been struggling with compile-time strings for quite a few years now - as the standard (library) string, std::string , requires dynamic memory allocation, and isn't constexpr. So we have a bunch of questions and blog posts about how to get compile-time strings right: Conveniently Declaring Compile-Time Strings in C++ Concatenate compile-time strings in a template at compile time? C++ Compile-Time string manipulation (off-site) Compile-time strings with

Will std::string end up being our compile-time string after all?

老子叫甜甜 提交于 2020-07-15 04:14:24
问题 Many developers and library authors have been struggling with compile-time strings for quite a few years now - as the standard (library) string, std::string , requires dynamic memory allocation, and isn't constexpr. So we have a bunch of questions and blog posts about how to get compile-time strings right: Conveniently Declaring Compile-Time Strings in C++ Concatenate compile-time strings in a template at compile time? C++ Compile-Time string manipulation (off-site) Compile-time strings with