Skip to content

Commit d7ad596

Browse files
authored
Merge pull request #6 from codecrafters-io/CC-1274-cpp
Add support for C++
2 parents 7e0cdf7 + 73f0b81 commit d7ad596

30 files changed

+513
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto

compiled_starters/cpp/.gitignore

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Prerequisites
2+
*.d
3+
4+
# Compiled Object files
5+
*.slo
6+
*.lo
7+
*.o
8+
*.obj
9+
10+
# Precompiled Headers
11+
*.gch
12+
*.pch
13+
14+
# Compiled Dynamic libraries
15+
*.so
16+
*.dylib
17+
*.dll
18+
19+
# Fortran module files
20+
*.mod
21+
*.smod
22+
23+
# Compiled Static libraries
24+
*.lai
25+
*.la
26+
*.a
27+
*.lib
28+
29+
# Executables
30+
*.exe
31+
*.out
32+
*.app
33+
server
34+
35+
# CMake
36+
CMakeLists.txt.user
37+
CMakeCache.txt
38+
CMakeFiles
39+
CMakeScripts
40+
Testing
41+
Makefile
42+
cmake_install.cmake
43+
install_manifest.txt
44+
compile_commands.json
45+
CTestTestfile.cmake
46+
_deps
47+
48+
build/
49+
vcpkg_installed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
cmake_minimum_required(VERSION 3.13)
2+
3+
project(shell-starter-cpp)
4+
5+
file(GLOB_RECURSE SOURCE_FILES src/*.cpp src/*.hpp)
6+
7+
set(CMAKE_CXX_STANDARD 23) # Enable the C++23 standard
8+
9+
add_executable(shell ${SOURCE_FILES})

compiled_starters/cpp/README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
![progress-banner](https://codecrafters.io/landing/images/default_progress_banners/shell.png)
2+
3+
This is a starting point for C++ solutions to the
4+
["Build Your Own Shell" Challenge](https://app.codecrafters.io/courses/shell/overview).
5+
6+
In this challenge, you'll build your own POSIX compliant shell that's capable of
7+
interpreting shell commands, running external programs and builtin commands like
8+
cd, pwd, echo and more. Along the way, you'll learn about shell command parsing,
9+
REPLs, builtin commands, and more.
10+
11+
**Note**: If you're viewing this repo on GitHub, head over to
12+
[codecrafters.io](https://codecrafters.io) to try the challenge.
13+
14+
# Passing the first stage
15+
16+
The entry point for your `shell` implementation is in `src/main.cpp`. Study and
17+
uncomment the relevant code, and push your changes to pass the first stage:
18+
19+
```sh
20+
git add .
21+
git commit -m "pass 1st stage" # any msg
22+
git push origin master
23+
```
24+
25+
Time to move on to the next stage!
26+
27+
# Stage 2 & beyond
28+
29+
Note: This section is for stages 2 and beyond.
30+
31+
1. Ensure you have `cmake` installed locally
32+
1. Run `./your_shell.sh` to run your program, which is implemented in
33+
`src/main.cpp`.
34+
1. Commit your changes and run `git push origin master` to submit your solution
35+
to CodeCrafters. Test output will be streamed to your terminal.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Set this to true if you want debug logs.
2+
#
3+
# These can be VERY verbose, so we suggest turning them off
4+
# unless you really need them.
5+
debug: false
6+
7+
# Use this to change the C++ version used to run your code
8+
# on Codecrafters.
9+
#
10+
# Available versions: cpp-23
11+
language_pack: cpp-23

compiled_starters/cpp/src/main.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include <iostream>
2+
3+
int main() {
4+
// Flush after every std::cout / std:cerr
5+
std::cout << std::unitbuf;
6+
std::cerr << std::unitbuf;
7+
8+
// You can use print statements as follows for debugging, they'll be visible when running tests.
9+
std::cout << "Logs from your program will appear here!\n";
10+
11+
// Uncomment this block to pass the first stage
12+
// std::cout << "$ ";
13+
//
14+
// std::string input;
15+
// std::getline(std::cin, input);
16+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"default-registry": {
3+
"kind": "git",
4+
"baseline": "c4af3593e1f1aa9e14a560a09e45ea2cb0dfd74d",
5+
"repository": "https://github.com/microsoft/vcpkg"
6+
},
7+
"registries": [
8+
{
9+
"kind": "artifact",
10+
"location": "https://github.com/microsoft/vcpkg-ce-catalog/archive/refs/heads/main.zip",
11+
"name": "microsoft"
12+
}
13+
]
14+
}

compiled_starters/cpp/vcpkg.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"dependencies": []
3+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/sh
2+
#
3+
# DON'T EDIT THIS!
4+
#
5+
# CodeCrafters uses this file to test your code. Don't make any changes here!
6+
#
7+
# DON'T EDIT THIS!
8+
set -e
9+
# vcpkg & cmake are required.
10+
cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake
11+
cmake --build ./build
12+
exec ./build/shell "$@"

course-definition.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ languages:
2222
- slug: "java"
2323
- slug: "javascript"
2424
- slug: "c"
25+
- slug: "cpp"
2526
- slug: "typescript"
2627

2728
marketing:

0 commit comments

Comments
 (0)