COMS W4995 C++ Deep Dive for C Programmers

Index of 2025-9/code/01

Parent directory
Makefile
hello.cpp

Makefile

CC  = g++
CXX = g++

CFLAGS   = -g -Wall
CXXFLAGS = -g -Wall -std=c++20

hello: hello.o

hello.o: hello.cpp

.PHONY: clean
clean:
	rm -f *.o hello

.PHONY: all
all: clean hello

hello.cpp

#include <iostream>

namespace c2cpp {

    int main() {
        using namespace std;

        string s;

        s = "hello ";
        s = s + "world ";

        // Shouldn't the following line be the same thing?
        // s = "hello " + "world ";

        // What about this?
        // s = s + 100;

        // Or this?
        // s += 100;  // Try changing 100 to 101 to see what's going on

        cout << s << "c" << 2 << "cpp!" << endl;
        return 0;
    }

} // namespace c2cpp

int main() {
    return c2cpp::main();
}