Guest User

Untitled

a guest
Oct 19th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstddef>
  3. #include <string>
  4. using namespace std;
  5.  
  6. string textWrap(string str, int chars) {
  7. string end = "n";
  8.  
  9. int charTotal = str.length();
  10. while (charTotal>0) {
  11. if (str.at(chars) == ' ') {
  12. str.replace(chars, 1, end);
  13. }
  14. else {
  15. str.replace(str.rfind(' ',chars), 1, end);
  16. }
  17. charTotal -= chars;
  18. }
  19. return str;
  20. }
  21.  
  22. //function call
  23. cout << textWrap("I want to wrap this text after about 15 characters please.", 15);
  24.  
  25. std::string textWrap(string str, int location) {
  26. str.at(str.rfind(" ", location)) = 'n';
  27. return str;
  28. }
  29.  
  30. int main(){
  31. std::cout << textWrap("I want to wrap this text after about 15 characters please.", 15);
  32. }
Add Comment
Please, Sign In to add comment