0% found this document useful (0 votes)
16 views

Strings

This C++ code declares and manipulates string variables using pointers and references. It demonstrates initializing strings, concatenating strings, accessing characters within strings, and finding substrings within strings.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Strings

This C++ code declares and manipulates string variables using pointers and references. It demonstrates initializing strings, concatenating strings, accessing characters within strings, and finding substrings within strings.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

#include <iostream>

using namespace std;

int main() {

string* sp = new string;


*sp = "def";
cout << sp << endl;
cout << *sp << endl;

string s = "abc";
//getline(cin, s);
cout << s << endl;

s = "defdef";
cout << s[0] << endl;
s[0] = 'a';
string s1;
s1 = "def";

string s2 = s + s1;
cout << s2 << endl;

s += s1;

cout << s1 << endl;


cout << s << endl;

cout << s.size() << endl;


cout << s.substr(3) << endl;
cout << s.substr(3, 3) << endl;

cout << s.find("def") << endl;

You might also like