Skip to main content
Advice
1 vote
5 replies
162 views

Why can't you just do this? int index = 0; std::string example; std::cin >> example; std::vector<std::string> list; list.push_back(example[index]); I'm a complete beginner in c++ and I ...
Filipos's user avatar
8 votes
1 answer
571 views

The following test code causes a double free error on gcc 8.5 or lower when run with g++ test.cpp -O2 -std=c++1z -fnon-call-exceptions. On other gcc versions like 9.1 or higher it doesn't. See ...
JR_1's user avatar
  • 93
-2 votes
1 answer
184 views

class string { struct long_mode { size_t size; size_t capacity; char* buffer; }; struct short_mode { uint8_t size; char buffer[23]; }; ...
Renat's user avatar
  • 5
Advice
0 votes
30 replies
159 views

cppreference.com says: std::basic_string<CharT,Traits,Allocator>::basic_string Throws std::length_error if the length of the constructed string would exceed max_size() (for example, if count &...
Spook's user avatar
  • 87
0 votes
1 answer
109 views

I have this demo. It fails to compile if the provided initialisation string for constexpr std::string OVERFLOW = is longer than the default capacity of 15. I understand why, but I am not aware of ...
Peter VARGA's user avatar
  • 5,371
2 votes
1 answer
167 views

I need to set the result from std::put_time from ctime into a std::string, how do I do this ? Here is my code: BBToolkit::LogManager::LogManager() { auto t = std::time(nullptr); auto tm = *std:...
joris studios's user avatar
5 votes
0 answers
182 views

I observe rather strange behavior of Visual Studio's compiler with short strings during constant evaluation, as can be demonstrated by this example: #include <string> constexpr char f( const ...
Fedor's user avatar
  • 25.6k
2 votes
1 answer
173 views

I want to create the following string: "name_1,name_2,...,name_100". This can be accomplished using the following code: #include <format> #include <string> // ... const auto ...
PlsHelp's user avatar
  • 347
3 votes
0 answers
155 views

I seem to run into issue with the use of std::ssize in C++. I am able to compile in string.cpp but not string_quiz.cpp. I ran this code with g++ -o string_quiz -std=c++23 string_quiz.cpp string_quiz....
dansyw91's user avatar
3 votes
1 answer
137 views

For this simple classes below. For MyClass, the constructor initializes str with s during construction using the intializer list. Does this mean that str doesn't get constructed at all yet until mc ...
Engineer999's user avatar
  • 4,159
1 vote
2 answers
331 views

If I have an empty string and I do .resize() I expected the size and the capacity to be that size. That is not the case in GCC or Clang or MSVC. Requesting a size of 17 gives you a capacity of 30 or ...
Zebrafish's user avatar
  • 16.9k
1 vote
0 answers
59 views

I'm trying to convert an std::array of integers to a string for output, so I tried using this string constructor: template< class InputIt > basic_string( InputIt first, InputIt last, const ...
venyanwarrior's user avatar
9 votes
0 answers
290 views

I want a templated function that calls a method of its template class depending on which class it is. I understand that a better way to achieve this would be using std::is_same, but irrelevant for the ...
Ivan Gorin's user avatar
2 votes
2 answers
125 views

I'm a bit lost why Option 1 doesn't work. In my understanding I should be able to write to a presized std::string whatever I want as long as I don't overshoot the string size, but it doesn't work on ...
glades's user avatar
  • 5,466
1 vote
1 answer
151 views

I wish to optimise the use of const string literals in a bulky c++ 20 project to enhance compilation and runtime performance In lots of source files string literals are declared with const std::string ...
MikyMax's user avatar
  • 11

15 30 50 per page
1
2 3 4 5
82