Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Oppiskele Common String Methods | Text Data Type
C++ Data Types

bookCommon String Methods

append.h

append.h

copy
1
str.append("added part");
main.cpp

main.cpp

copy
12345678
#include <iostream> int main() { std::string str = "Code"; str = str + "finity"; // or str += "finity" std::cout << str << std::endl; }
main.cpp

main.cpp

copy
12345678
#include <iostream> int main() { std::string str = "finity"; str = "code" + str + ".com"; std::cout << str << std::endl; }
insert.h

insert.h

copy
1
str.insert(pos, "text to add");
replace.h

replace.h

copy
1
str.replace(start, n, "new text");
erase.h

erase.h

copy
1
str.erase(start, n);
main.cpp

main.cpp

copy
123456789101112131415161718192021
#include <iostream> int main() { std::string str = "finity"; str.append(".com"); // finity to finity.com std::cout << str << std::endl; str = "in" + str; // finity.com to infinity.com std::cout << str << std::endl; str.insert(2, "de"); // infinity.com to indefinity.com std::cout << str << std::endl; str.replace(0, 2, "co"); // indefinity.com to codefinity.com std::cout << str << std::endl; str.erase(10, 4); // codefinity.com to codefinity std::cout << str << std::endl; }

Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 3. Luku 4

Kysy tekoälyä

expand

Kysy tekoälyä

ChatGPT

Kysy mitä tahansa tai kokeile jotakin ehdotetuista kysymyksistä aloittaaksesi keskustelumme

Suggested prompts:

Can you show examples of how each string method works?

What is the difference between .append() and concatenation with +?

How does the .replace() method work with different values of start and n?

Awesome!

Completion rate improved to 4.35

bookCommon String Methods

Pyyhkäise näyttääksesi valikon

append.h

append.h

copy
1
str.append("added part");
main.cpp

main.cpp

copy
12345678
#include <iostream> int main() { std::string str = "Code"; str = str + "finity"; // or str += "finity" std::cout << str << std::endl; }
main.cpp

main.cpp

copy
12345678
#include <iostream> int main() { std::string str = "finity"; str = "code" + str + ".com"; std::cout << str << std::endl; }
insert.h

insert.h

copy
1
str.insert(pos, "text to add");
replace.h

replace.h

copy
1
str.replace(start, n, "new text");
erase.h

erase.h

copy
1
str.erase(start, n);
main.cpp

main.cpp

copy
123456789101112131415161718192021
#include <iostream> int main() { std::string str = "finity"; str.append(".com"); // finity to finity.com std::cout << str << std::endl; str = "in" + str; // finity.com to infinity.com std::cout << str << std::endl; str.insert(2, "de"); // infinity.com to indefinity.com std::cout << str << std::endl; str.replace(0, 2, "co"); // indefinity.com to codefinity.com std::cout << str << std::endl; str.erase(10, 4); // codefinity.com to codefinity std::cout << str << std::endl; }

Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 3. Luku 4
some-alt