C++ String insert()Last Updated : 17 Mar 2025 This function is used to insert a new character, before the character indicated by the position pos. SyntaxConsider two strings str1 and str2, pos is the positon. Syntax would be : Parametersstr : String object to be inserted in another string object. pos : It defines the position at which new content is inserted just before the specified position. subpos : It defines the position of first character in string str which is to be inserted in another string object. sublen : It defines the number of characters of string str to be inserted in another string object. n : It determines the number of characters to be inserted. c : Character value to insert. Example 1Let's see the simple example. Output: String contains : javat tutorial After insertion, String value is javatpoint tutorial Example 2Let's the simple example of insertion when subpos and sublen are given. Output: String contains C++ is a language After insertion, String is C++ is a programming language Example 3Let's see the simple example of insertion when number of characters to be inserted are given. Output: String contains : Maths is favorite subject
After insertion, String contains : Maths is my favorite subject
Next TopicC++ Strings |
We request you to subscribe our newsletter for upcoming updates.

We deliver comprehensive tutorials, interview question-answers, MCQs, study materials on leading programming languages and web technologies like Data Science, MEAN/MERN full stack development, Python, Java, C++, C, HTML, React, Angular, PHP and much more to support your learning and career growth.
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India