Похожие чаты

Hi guys. void reverse(string str) { string tmp;

unsigned int l = str.length();
tmp.reserve(l);
for(auto *end = &str[l-1]; *end >= str[0]; --*end) {
tmp += *end;
}
cout << tmp;
}
Is this a good way to reverse a string? Or is there a better way?
Note that I am just doing what I remember from the book(which I've just read(without any good practice) this summer), so I may have written stupid things.
Actually I don't reverse, I know. But this is just a test

4 ответов

8 просмотров
Hayk-Zneigras Автор вопроса

Yesterday I was having a trouble with int/uint so I decided to do this.

the exit condition seems funny

It would be a good way if it was not undefined behaviour that fails on all architectures ever made by IBM or on any place that doesn't guarantee that char and unsigned char behave the same

But I still prefer string reversed{original.rbegin(), original.rend()}; When I want to go original

Похожие вопросы

Обсуждают сегодня

Если у меня есть такой класс: Object = {} function Object:new(a_name, a_transform, a_color, a_mesh, a_material, a_shader, a_textures) local private = {} private.n...
Cuarno Vile
4
А кто-то пробовал, уезжая из Эстонии получить э-рез и продолжить вести предпринимательскую деятельность внутри Эстонии, используя свой OÜ?
Lalalashechki Lalala
62
Is Kadena onto something special? No one really knows. Good luck!
Bright Uncle Stephen EqualBet
40
At which price point will BCH, an ASIC mined coin, be succeptible to reorg attacks because of low hashrate? $10? $1? $0.1? $0.01?
Kishniev
18
зачем же переименовывать ? чтобы кол-во участников возросло или вдруг IBM от этого снова на свифте начнет кодить ? Я не понимаю что страшного в том что свифт гавно, если это т...
Oleh Nerzh
10
я не магистр хаскеля, но разве не может лейзи тип конвертнуться в не-лейзи запросив вычисление содержимого прям при инициализации?
deadgnom32 λ madao
100
Гайз, кто-нибудь пробовал запустить probe-rs под камень, которого нет в probe-rs? Мб есть какой-нибудь пример у кого... Через target-gen попробовал сгенерировать chip-descript...
Максим Смирнов
2
здравствуйте. совершаю вот такую вещь: strcpy(line, (char)current_number); где current number — неподписанный шорт, line — массив чаров. ругань следующая: main.c:29:30: error...
Roberto's Ширгозиев
13
@MrMiscipitlick А можешь макрос написать, который будет вычислять смещение относительно переданных меток? Просто .label1-.label2, и вернуть значение.
КТ315
35
Hello VIC team, I had previously used the “wallet.tomochain.com” with a ledger connection. Unfortunately, the site is no longer accessible and the ledger account is not visibl...
carpe noctem
7
Карта сайта