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?????

Recommended Answers

All 3 Replies

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>.

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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.