Dashboard/Block 1: Foundation/Module 3
Module 3Foundation

Introduction to C++ & Strings

Alright, big moment — this week you are making the jump from C to C++. Now, do not worry, you are not throwing away everything you learned. C++ is basically C with superpowers. Almost all the C code you have written so far is also valid C++. Think of it like this: if C is a bicycle, C++ is that same bicycle but with an electric motor strapped on. Everything you already know still works, you just have some really nice extras now.

So what are these extras? Three big ones this week. First, cout and cin replace printf and scanf — and honestly, they are so much nicer. No more memorizing format specifiers like %d or %f — C++ figures out the type for you automatically. Second, the std::string class replaces those awkward C-style char arrays. Strings in C++ can grow on their own, you can smash them together with +, compare them with ==, and use handy methods like .length(), .substr(), and .find(). Third, you will learn about namespaces, which is C++'s way of keeping code organized so names do not clash — the std namespace is where all the standard library stuff lives.

C WayC++ WayWhy C++ Is Better
printf("%d", x);cout << x;No format specifiers needed — type is detected automatically
scanf("%s", name);cin >> name;No & needed, and no buffer overflow risk with string
char name[50];string name;No fixed size — strings grow and shrink as needed
strcmp(a, b) == 0a == bDirect comparison with == instead of a function call
strcat(a, b);a + bConcatenation with the + operator

By the end of this week, you will be writing cleaner, more modern code using C++ I/O streams, the string class, and namespaces. The tedious and error-prone C-style string handling? You are leaving that behind.

Learning Objectives

Use cout and cin instead of printf and scanf
Work with the std::string class and its operations
Use getline for reading full lines of input
Understand namespaces and 'using namespace std'
Perform string operations: length, substr, find, concatenation

Key Concepts

From C to C++: cout & cin

The string Class

getline and Namespaces