PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, May 12, 2022

[FIXED] How can we insert a character to a string in c++?

 May 12, 2022     append, c++, string     No comments   

Issue

INPUT STRING

ABCE

INPUT CHAR

D

OUTPUT STRING

ABCDE

It should run for all sizes , and it should be a standard procedure ie run for all the cases. Can anyone Help me with this? Any help would be appreciated.


Solution

You should try the std::string::insert(..). Check out the documentation

#include <iostream>
#include <string>

int main() {
    std::string str("ABCE");
    std::cout << str << std::endl; // ABCE

    str.insert(3, 1, 'D');
    std::cout << str << std::endl; // ABCDE

    return -1;
}


Answered By - Caglayan DOKME
Answer Checked By - Marilyn (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing