Introduction To Computer Science PDF Fall 2024

Summary

Lecture notes for Introduction to Computer Science, Fall 2024, from ETH Zurich. The document covers characters and texts in programming..

Full Transcript

INTRODUCTION TO COMPUTER SCIENCE 252-0032, 252-0047, 252-0058 Document authors: Manuela Fischer and Felix Friedrich Department of Computer Science, ETH Zurich Fall 2024 1 Characters and Texts...

INTRODUCTION TO COMPUTER SCIENCE 252-0032, 252-0047, 252-0058 Document authors: Manuela Fischer and Felix Friedrich Department of Computer Science, ETH Zurich Fall 2024 1 Characters and Texts 128 Section 10 Characters and Texts We have seen texts before: std::cout 0 // POST: returns the mathematically defined remainder of // dividend / divisor with 0 = 32 && c > std::noskipws; // #include char next; while (std::cin >> next){ std::cout > s; // Shift input by s caesar(s); return 0; } Code 10.1: Reading a shift value and a text from standard input and writing the encoded text to standard output. ˆ Comparing texts: if (text1 == text2)... true if character-wise equal ˆ Querying size: int length = text.size(); Characters and Texts 132 Size not equal to text length if multi-byte encoding is used, e.g. UTF-8 ˆ Reading single characters: if (text == 'a')... //or text.at(0) text does not check index bounds, whereas text.at(0) does ˆ Writing single characters: text = 'b'; //or text.at(0) ˆ Iteration over characters: for (int i = 0; i < int(text.size()); ++i) std::cout

Use Quizgecko on...
Browser
Browser