0

Okay, so I know how to reverse the whole string of a vector,

[code]for_each(newLines.begin(), newLines.end(), [](std::string& s){ reverse(s.begin(), s.end()); });
copy(newLines.begin(), newLines.end(), std::ostream_iterator<std::string> (std::cout, "\n")); [/code]

But is there a way to only reverse the first 10 or so characters of a vector string? i.e.

sdjkfskjd sfdsdf sdjflkjsdjklfsdlkjflksdjfkls jklda sdfioss sloidfjosdf

I only want to reverse the "sdjkfskjd" and not the rest of the string?????

3
Contributors
3
Replies
14
Views
3 Years
Discussion Span
Last Post by tinstaafl
0

Change for_each(newLines.begin(), newLines.end(), [](std::string& s){ reverse(s.begin(), s.end()); }); to for_each(newLines.begin(), newLines.end(), [](std::string& s){ reverse(s.begin(), s.begin() + 10); }); to only do the first 10 characters. I assume newLines is of type std::vector<std::string>.

Edited by NathanOliver

0

Yes newLine is the vector string. I will give it a try, thanks.

0

It's hard to tell exactly what you mean without functioning code. The snippet you gave, isn't complete and it's not formatted at all.

Edited by tinstaafl

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.