- a collection of native C++ classes libraries, similar to the .NET Framework;
- written in efficient, modern C++14;
- and highly portable and available on many different platforms (Windows, macOS, Linux, iOS and android);
For more information see Switch website (or markdown Documentations) and Reference Guide
The classic first application 'Hello World'.
HelloWorld.cpp:
#include <Switch/Switch>
using namespace System;
namespace HelloWorld {
class Program {
public:
static void Main() {
Console::WriteLine("Hello, World!");
}
};
}
startup_(HelloWorld::Program);
CMakeLists.txt:
cmake_minimum_required(VERSION 3.2)
Project(HelloWorld)
find_package(Switch REQUIRED)
add_executable(HelloWorld HelloWorld.cpp)
target_link_libraries(HelloWorld Switch.System)
HelloWorldForm.cpp:
#include <Switch/Switch>
using namespace System;
using namespace System::Drawing;
using namespace System::Windows::Forms;
namespace HelloWorld {
class Program {
public:
static void Main() {
Application::EnableVisualStyles();
Button button;
button.Text = "Click me";
button.Location = Point(10, 10);
button.Click += delegate_(const object& sender, const EventArgs& e) {
MessageBox::Show("Hello, World!");
};
Form form;
form.Text = "Hello World Form";
form.Controls().Add(button);
Application::Run(form);
}
};
}
startup_(HelloWorld::Program);
CMakeLists.txt:
cmake_minimum_required(VERSION 3.2)
Project(HelloWorldForm)
find_package(Switch REQUIRED)
add_executable(HelloWorldForm ${SWITCH_GUI} HelloWorldForm.cpp)
target_link_libraries(HelloWorldForm Switch.System.Windows.Forms)
HelloWorldTest.cpp:
#include <Switch/Switch>
using namespace TUnit::Framework;
using namespace System;
namespace UnitTests {
class TestFixture_(HelloWorldTest) {
void Test_(CreateStringFromLiteral) {
string s = "Hello, World!";
Assert::AreEqual("Hello, World!", s);
}
void Test_(CreateStringFromChars) {
string s = {'H', 'e', 'l', 'l', 'o', ',', ' ', 'W', 'o', 'r', 'l', 'd', '!'};
Assert::AreEqual("Hello, World!", s);
}
};
AddTestFixture_(HelloWorldTest);
}
CMakeLists.txt:
cmake_minimum_required(VERSION 3.2)
Project(HelloWorldTest)
find_package(Switch REQUIRED)
add_executable(HelloWorldTest HelloWorldTest.cpp)
target_link_libraries(HelloWorldTest Switch.TUnit.Main)
For more examples see Examples
Before running examples you must download and install Switch. To download and install it read Downloads page or Downloads.md file.