• Wrong document? Swap it for free
  • Written by students who passed
  • Immediately available after payment
  • Read online or as PDF
Sell
Where do you study
Your language
Document preview thumbnail
Preview 3 out of 21 pages
Exam (elaborations)

String and Vector Functions in C++

Document preview thumbnail
Preview 3 out of 21 pages

String and Vector Functions in C++

Content preview

String and Vector Functions in C++

1. isalnum cctype or ctype.h library what does it have (13
isalpha but know the two big ones)
isblank
iscntrl
isdigit
isgraph
islower
isprint
ispunct
isspace
isupper
tolower
toupper

2. isprint(c) Returns true if c is a printable character. Print-
able characters include alphanumeric, punctu-
ation, and space characters.

3. iscntrl(c) Returns true if c is a control character. Control
characters are all characters that are not print-
able.

4. isxdigit(c) Returns true if c is a hexadecimal digit: 0-9, a-f,
A-F.

5. length(), [], push_back, substr what is included in <string>

6. pop_back(), push_back(), size() what is included in <vector>

7. char greeting2[] = "Hello"; // C-Style string greeting1 = "Hello"; // Regular String
String (an array of characters)

8. at()



, String and Vector Functions in C++

Returns the character at a specified index, with
bounds checking

9. back() Accesses the last character in the string

10. begin() Returns an iterator pointing to the first character
of the string

11. std::string myStr = "Hello"; explain .c_str() (give an example)
const char* cString = myStr.c_str();

myStr is a std::string
cString now points to a null-terminated
character array like "Hello\0"

12. C++: s.length() or s.size() Q: How do you find the length of a string?
C-style: strlen(s) (from <cstring>)

13. A: Q: How do you concatenate strings?
C++: s1 + s2, s += "text"
C-style: strcat(dest, src)

14. A: Q: How do you declare a C++ string vs. a C-style
std::string s = "Hello"; (needs #include string?
<string>)
char s[] = "Hello";

15. A: Q: How do you copy strings?
C++: std::string copy = original;
C-style: strcpy(dest, src)

16. A: Q: How do you compare strings for equality?
C++: s1 == s2
C-style: strcmp(s1, s2) == 0


, String and Vector Functions in C++


17. A: Q: How do you access individual characters in a
Both: s[i] string?
C++ also supports s.at(i) with bounds
checking

18. A: Q: How do you get a substring?
C++: s.substr(start, length)
C-style: No direct function; use strncpy()
manually

19. A: Q: How do you find a word inside a string (po-
C++: s.find("word") sition)?
std::string text = "Welcome to Earth"; give examples for both
size_t pos = text.find("Earth"); // returns
index of "Earth"

C-style: strstr(s, "word")
char text[] = "Welcome to Earth";
char* found = strstr(text, "Earth");
if (found != nullptr) {
int pos = found - text;

strstr() returns a pointer, so subtracting
the base address gives you the index.

20. A: Q: How do you replace part of a string? + exam-
C++: s.replace(pos, len, "new") ples
std::string s = "I love apples"; "I love apples" --> I hate apples
s.replace(2, 4, "hate");


C-style: Manually with strncpy()

Document information

Uploaded on
June 28, 2025
Number of pages
21
Written in
2024/2025
Type
Exam (elaborations)
Contains
Questions & answers
$22.49

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
BestwriterGuru
4.8
(729)
Sold
301
Followers
34
Items
6078
Last sold
1 day ago



Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions