Похожие чаты

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 ответов

26 просмотров
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

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

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

Господа, а что сейчас вообще с рынком труда на делфи происходит? Какова ситуация?
Rꙮman Yankꙮvsky
29
А вообще, что может смущать в самой Julia - бы сказал, что нет единого стандартного подхода по многим моментам, поэтому многое выглядит как "хаки" и произвол. Короче говоря, с...
Viktor G.
2
@Benzenoid can you tell me the easiest, and safest way to bu.y HEX now?
Živa Žena
20
This is a question from my wife who make a fortune with memes 😂😂 About the Migration and Tokens: 1. How will the old tokens be migrated to the new $LGCYX network? What is th...
🍿 °anton°
2
30500 за редактор? )
Владимир
47
а через ESC-код ?
Alexey Kulakov
29
What is the Dex situation? Agora team started with the Pnetwork for their dex which helped them both with integration. It’s completed but as you can see from the Pnetwork ann...
Ben
1
Гайс, вопрос для разносторонее развитых: читаю стрим с юарта, нада выделять с него фреймы с определенной структурой, если ли чо готовое, или долбаться с ринг буффером? нада у...
Vitaly
9
Anyone knows where there are some instructions or discort about failed bridge transactions ?
Jochem
21
@lozuk how do I get my phex copies of my ehex from a atomic wallet, to move to my rabby?
Justfrontin 👀
11
Карта сайта