Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

seanpm2001/Learn-C-Plus-Plus

Repository files navigation


Learning C++

/ISO_C++_Logo.svg

Hello World in C++

#include <iostream>

int main()
{
    std::cout << "Hello, world!\n";
}

This program uses the C++ standard library to write a Hello World program. It is incredibly simple to the syntax of C, the major difference in this example being printf instead being std::cout << (std::cout stands for something, but I can't find info. I think cout stands for C output but I am not sure)

Comments in C++

Comments in C++ are identical to comments in C.

// This is a single line comment
/* This
is a multiline
comment */
/* Multi-line comments
* can also
* be written
* like this */

Break keyword in C++

break;

To this day, I am still not entirely sure what the break keyword does, but most languages support it.

/!\ This example has not been tested yet, and may not work

If/else in C++

x = int(1)
if (x == 0) {
	bool isZeroBool = (true);
} else {
	bool isZeroBool = (false);
}

This is a pretty bad example.

/!\ This example has not been tested yet, and may not work

Classes in C++

One of the major differences between C and C++ is the inclusion of classes. There is a reason why C++ is commonly called C with classes

class superClass() {
	int main() {
		std::cout << "Superclass says: Hello World!";	
	}
	return main();
}

/!\ This example has not been tested yet, and may not work

Booleans in C++

In C++, the Boolean keyword is shortened to bool for this example, I expect you to know the basics of what a Boolean is (a true or false value, yes or no, 1 or 0)

input1 = string(input("Do you think C++ is good? y/N)"));
if input1 == "y" or "Y" {
	bool trueFalse = true;
} else {
	bool trueFalse = false;
}
std::cout << "You entered: " + trueFalse()

/!\ This example has not been tested yet, and may not work

Integers in C++

// This program exponentiates 2 and 16. The result should be 65536
int x = 2;
int y = 16;
cout << x ** y;

/!\ This example has not been tested yet, and may not work

Escape characters in C++

std::cout << "Newline?\nNewline! Tab?\tTab! Quotation Marks?\"Quotation Marks\" ";

/!\ This example has not been tested yet, and may not work

Strings in C++

cpp-with-plus = string("C++");
std::cout << cpp-with-plus;

/!\ This example has not been tested yet, and may not work

Return in C++

class superClass() {
	int main() {
		std::cout << "Superclass says: Hello World!";	
	}
	return main();
	std::cout << "Superclass returned: Superclass says: Hello World!";
}

This example is a slightly modified copy of the class section

/!\ This example has not been tested yet, and may not work

More C++

I have much more to list here, and much to learn.


About

A repository for showcasing my knowledge of the C++ programming language, and continuing to learn the language.

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

Packages

No packages published

Languages

Morty Proxy This is a proxified and sanitized view of the page, visit original site.