Inserts the characters "******" in the exact middle of a string. - C++ STL

C++ examples for STL:string

Description

Inserts the characters "******" in the exact middle of a string.

Demo Code

#include <iostream>
#include <string>

int main(int argc, const char* argv[]) {
    std::cout << "Enter a string: ";

    std::string base;//www . java  2 s .  c  o  m
    std::getline(std::cin, base);

    std::string insertStr = "******";

    base.insert((base.length() / 2), insertStr);

    std::cout << "\nNew String:\n" << base << std::endl;

    return 0;
}

Result


Related Tutorials