Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstddef>
- #include <string>
- using namespace std;
- string textWrap(string str, int chars) {
- string end = "n";
- int charTotal = str.length();
- while (charTotal>0) {
- if (str.at(chars) == ' ') {
- str.replace(chars, 1, end);
- }
- else {
- str.replace(str.rfind(' ',chars), 1, end);
- }
- charTotal -= chars;
- }
- return str;
- }
- //function call
- cout << textWrap("I want to wrap this text after about 15 characters please.", 15);
- std::string textWrap(string str, int location) {
- str.at(str.rfind(" ", location)) = 'n';
- return str;
- }
- int main(){
- std::cout << textWrap("I want to wrap this text after about 15 characters please.", 15);
- }
Add Comment
Please, Sign In to add comment