• ¿Documento equivocado? Cámbialo gratis
  • Escrito por estudiantes que aprobaron
  • Inmediatamente disponible después del pago
  • Leer en línea o como PDF
Vender
¿Dónde estudias?
Tu idioma
Document preview thumbnail
Vista previa 3 fuera de 21 páginas
Examen

String and Vector Functions in C++

Document preview thumbnail
Vista previa 3 fuera de 21 páginas

String and Vector Functions in C++

Vista previa del contenido

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()

Información del documento

Subido en
28 de junio de 2025
Número de páginas
21
Escrito en
2024/2025
Tipo
Examen
Contiene
Preguntas y respuestas
$22.49

¿Documento equivocado? Cámbialo gratis Dentro de los 14 días posteriores a la compra y antes de descargarlo, puedes elegir otro documento. Puedes gastar el importe de nuevo.
Escrito por estudiantes que aprobaron
Inmediatamente disponible después del pago
Leer en línea o como PDF

Seller avatar
Los indicadores de reputación están sujetos a la cantidad de artículos vendidos por una tarifa y las reseñas que ha recibido por esos documentos. Hay tres niveles: Bronce, Plata y Oro. Cuanto mayor reputación, más podrás confiar en la calidad del trabajo del vendedor.
BestwriterGuru
4.8
(729)
Vendido
301
Seguidores
34
Artículos
6078
Última venta
1 día hace



Por qué los estudiantes eligen Stuvia

Creado por compañeros estudiantes, verificado por reseñas

Calidad en la que puedes confiar: escrito por estudiantes que aprobaron y evaluado por otros que han usado estos resúmenes.

¿No estás satisfecho? Elige otro documento

¡No te preocupes! Puedes elegir directamente otro documento que se ajuste mejor a lo que buscas.

Paga como quieras, empieza a estudiar al instante

Sin suscripción, sin compromisos. Paga como estés acostumbrado con tarjeta de crédito y descarga tu documento PDF inmediatamente.

Student with book image

“Comprado, descargado y aprobado. Así de fácil puede ser.”

Alisha Student

Preguntas frecuentes