Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

cpp substring

#include <iostream>
#include <string>

using namespace std;

void cpp_strings()
{
    string unformatted_full_name { "StephenHawking" };

    string first_name = unformatted_full_name.substr(0, 7);
    // string first_name { unformatted_full_name, 0, 7 };
    string last_name = unformatted_full_name.substr(7, 7);
    string formatted_full_name = first_name + last_name;

    formatted_full_name.insert(7, " ");
    cout << formatted_full_name;
}

int main()
{
    cpp_strings();
    return 0;
}
Source by cppbyexample.com #
 
PREVIOUS NEXT
Tagged: #cpp #substring
ADD COMMENT
Topic
Name
2+9 =