iso646
#include <iostream>
int main() {
char c;
std::cin >> c;
std::cout << c;
}#include <iostream>
int main() {
char c = '\n';
std::cout << c;
}#include <iostream>
int main() {
char c = '\t';
std::cout << c;
}#include <iostream>
int main() {
char c;
std::cin >> c;
std::cout << c;
}#include <iostream>
int main() {
char c = '\n';
std::cout << c;
}#include <iostream>
int main() {
char c = '\t';
std::cout << c;
}#include <iostream>
int main() {
std::string s = "Hello, world!";
std::cout << s;
}#include <iostream>
int main() {
std::string s1 = "Hello, ";
std::string s2 = "world!";
std::cout << s1 + s2;
}#include <iostream>
int main() {
std::string s1 = "Hello";
std::string s2 = "World";
std::cout << (s1 == s2);
}#include <iostream>
int main() {
std::string s = "Hello, world!";
std::cout << s.find("world");
}#include <iostream>
int main() {
std::string s = "Hello, world!";
std::cout << s.replace(7, 5, "universe");
}#include <iostream>
int main() {
int n = 10;
std::cout << std::format("The number is {}", n);
}#include <iostream>
#include <regex>
int main() {
std::string s = "Hello, world!";
std::regex re("world");
std::cout << std::regex_match(s, re);
}#include <iostream>
#include <fstream>
int main() {
std::ifstream in("input.txt");
std::ofstream out("output.txt");
std::string line;
while (std::getline(in, line)) {
out << line << std::endl;
}
}#include <iostream>
#include <vector>
int main() {
std::vector<int> v = {1, 2, 3};
for (int n : v) {
std::cout << n << " ";
}
}#include <iostream>
#include <algorithm>
int main() {
std::vector<int> v = {1, 2, 3};
std::sort(v.begin(), v.end());
for (int n : v) {
std::cout << n << " ";
}
}#include <iostream>
class Person {
public:
std::string name;
int age;
Person(std::string name, int age) {
this->name = name;
this->age = age;
}
void print() {
std::cout << name << ", " << age;
}
};
int main() {
Person person("John", 30);
person.print();
}#include <iostream>
int main() {
try {
// Code that may throw an exception
} catch (std::exception& e) {
// Code to handle the exception
}
}#include <iostream>
template<typename T>
T max(T a, T b) {
return a > b ? a : b;
}
int main() {
std::cout << max(1, 2);
}#include <iostream>
int main() {
int n = 10;
auto lambda = [n](int x) { return x + n; };
std::cout << lambda(5);
}#include <iostream>
#include <thread>
int main() {
std::thread thread([] {
// Code to be executed in a separate thread
});
thread.join();
}#include <iostream>
int main() {
int n;
while (!(std::cin >> n)) {
std::cout << "Invalid input";
}
}#include <iostream>
#include <stdexcept>
int main() {
try {
// Code that may throw an exception
} catch (std::invalid_argument& e) {
std::cout << e.what();
}
}#include <iostream>
#include <cassert>
int main() {
int n;
std::cin >> n;
assert(n > 0);
// ...
}#include <iostream>
#include <gtest/gtest.h>
TEST(UnitTest, Test1) {
// Assertions and tests
}
int main(int argc, char** argv) {
return RUN_ALL_TESTS();
}#include <iostream>
#include <spdlog/spdlog.h>
int main() {
auto logger = spdlog::stdout_logger_mt("console");
logger->info("Hello, world!");
}#include <iostream>
#include <boost/program_options.hpp>
int main(int argc, char** argv) {
boost::program_options::options_description desc("Options");
desc.add_options()
("help,h", "Show help message")
("config,c", boost::program_options::value<std::string>(), "Configuration file");
boost::program_options::variables_map vm;
boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm);
if (vm.count("help")) {
std::cout << desc << std::endl;
return 0;
}
std::string configFile;
if (vm.count("config")) {
configFile = vm["config"].as<std::string>();
}
// ...
}#include <iostream>
#include <boost/asio.hpp>
int main() {
boost::asio::io_service io_service;
boost::asio::ip::tcp::acceptor acceptor(io_service, boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), 12345));
for (;;) {
boost::asio::ip::tcp::socket socket(io_service);
acceptor.accept(socket);
// ...
}
}#include <iostream>
#include <sqlite3.h>
int main() {
sqlite3* db;
sqlite3_open("database.db", &db);
sqlite3_stmt* stmt;
sqlite3_prepare_v2(db, "SELECT * FROM table", -1, &stmt, NULL);
while (sqlite3_step(stmt) == SQLITE_ROW) {
// ...
}
sqlite3_finalize(stmt);
sqlite3_close(db);
}#include <iostream>
#include <opencv2/opencv.hpp>
int main() {
cv::Mat image = cv::imread("image.jpg");
cv::cvtColor(image, image, cv::COLOR_BGR2GRAY);
cv::imshow("Image", image);
cv::waitKey(0);
}#include <iostream>
#include <wx/wx.h>
class MyApp : public wxApp {
public:
bool OnInit() override {
wxFrame* frame = new wxFrame(NULL, -1, "wxWidgets Example", wxPoint(50, 50), wxSize(450, 340));
frame->Show();
return true;
}
};
wxIMPLEMENT_APP(MyApp);#include <iostream>
#include <boost/beast.hpp>
int main() {
boost::beast::http::server server;
server.listen(boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), 8080));
server.run();
}#include <iostream>
#include <aws/s3/S3Client.h>
int main() {
Aws::S3::S3Client s3Client;
Aws::S3::Model::HeadBucketRequest request;
request.SetBucket("my-bucket");
auto outcome = s3Client.HeadBucket(request);
if (outcome.IsSuccess()) {
std::cout << "Bucket found" << std::endl;
} else {
std::cout << "Bucket not found" << std::endl;
}
}#include <iostream>
#include <mlpack/core.hpp>
int main() {
arma::mat data = arma::randn(100, 10);
arma::rowvec labels = arma::randi<arma::rowvec>(100, arma::distr_param(0, 2));
mlpack::svm::LinearSVMClassifier classifier(data, labels);
classifier.Train();
// ...
}#include <iostream>
#include <boost/spirit/home/qi.hpp>
#include <boost/spirit/home/karma.hpp>
int main() {
std::string input = "John Doe, 30, Software Engineer";
boost::spirit::qi::grammar<std::string::iterator, std::tuple<std::string, int, std::string>()> grammar;
grammar = boost::spirit::qi::eps >> boost::spirit::qi::phrase_parse(
input.begin(), input.end(),
boost::spirit::qi::lit("John") >> boost::spirit::qi::lit("Doe") >> boost::spirit::qi::int_ >> boost::spirit::qi::lit("Software") >> boost::spirit::qi::lit("Engineer") >> boost::spirit::qi::eps
);
std::string name;
int age;
std::string occupation;
bool success = boost::spirit::qi::phrase_parse(input.begin(), input.end(), grammar, boost::spirit::qi::space, std::tie(name, age, occupation));
if (success) {
std::cout << "Name: " << name << ", Age: " << age << ", Occupation: " << occupation << std::endl;
}
}#include <iostream>
#include <opencv2/opencv.hpp>
#include <boost/filesystem.hpp>
int main() {
std::string path = "images/";
boost::filesystem::directory_iterator end_itr;
for (boost::filesystem::directory_iterator itr(path); itr != end_itr; ++itr) {
cv::Mat image = cv::imread(itr->path().string());
// ...
}
}#include <iostream>
#include <portaudio.h>
int main() {
PaStreamParameters inputParameters;
inputParameters.device = Pa_GetDefaultInputDevice();
inputParameters.channelCount = 1;
inputParameters.sampleFormat = paFloat32;
inputParameters.suggestedLatency = Pa_GetDeviceInfo(inputParameters.device)->defaultLowInputLatency;
inputParameters.hostApiSpecificStreamInfo = NULL;
PaStream* stream;
PaError err = Pa_OpenStream(&stream, &inputParameters, NULL, 44100, 1024, paNoFlag, NULL, NULL);
if (err != paNoError) {
std::cout << "Error opening stream: " << Pa_GetErrorText(err) << std::endl;
return 1;
}
err = Pa_StartStream(stream);
if (err != paNoError) {
std::cout << "Error starting stream: " << Pa_GetErrorText(err) << std::endl;
return 1;
}
while (1) {
float inputBuffer[1024];
err = Pa_ReadStream(stream, inputBuffer, 1024);
if (err != paNoError) {
std::cout << "Error reading stream: " << Pa_GetErrorText(err) << std::endl;
break;
}
// ...
}
err = Pa_StopStream(stream);
if (err != paNoError) {
std::cout << "Error stopping stream: " << Pa_GetErrorText(err) << std::endl;
return 1;
}
err = Pa_CloseStream(stream);
if (err != paNoError) {
std::cout << "Error closing stream: " << Pa_GetErrorText(err) << std::endl;
return 1;
}
return 0;
}#include <iostream>
#include <ros/ros.h>
int main(int argc, char** argv) {
ros::init(argc, argv, "node_name");
ros::NodeHandle nh;
ros::Subscriber sub = nh.subscribe("/topic_name", 10, callback);
ros::Publisher pub = nh.advertise<std_msgs::String>("/topic_name", 10);
ros::Rate loop_rate(10);
while (ros::ok()) {
ros::spinOnce();
loop_rate.sleep();
}
return 0;
}#include <iostream>
#include <bullet/btBulletDynamicsCommon.h>
int main() {
btDiscreteDynamicsWorld* world = new btDiscreteDynamicsWorld(NULL, NULL, NULL, NULL);
btBoxShape* groundShape = new btBoxShape(btVector3(btScalar(2.0), btScalar(2.0), btScalar(2.0)));
btRigidBody* groundBody = new btRigidBody(0, NULL, groundShape, btVector3(btScalar(0.0), btScalar(0.0), btScalar(0.0)));
world->addRigidBody(groundBody);
btCapsuleShape* capsuleShape = new btCapsuleShape(0.25, 0.5);
btTransform capsuleTransform;
capsuleTransform.setIdentity();
capsuleTransform.setOrigin(btVector3(1.0, 1.0, 0.0));
btRigidBody* capsuleBody = new btRigidBody(1.0, NULL, capsuleShape, btVector3(0.0, 0.0, 0.0));
capsuleBody->setWorldTransform(capsuleTransform);
world->addRigidBody(capsuleBody);
while (true) {
for (int i = 0; i < 10; i++) {
world->stepSimulation(0.1, 1);
}
// ...
}
return 0;
}#include <iostream>
#include <boost/optimization.hpp>
int main() {
boost::optimization::function<double> f = [](const std::vector<double>& x) {
return x[0] * x[0] + x[1] * x[1];
};
boost::optimization::minimizer minimizer;
minimizer.set_function(f);
boost::optimization::minimize(minimizer);
std::cout << "Minimum found at: (" << minimizer.x()[0] << ", " << minimizer.x()[1] << ")\n";
std::cout << "Minimum value: " << minimizer.value() << "\n";
}#include <iostream>
#include <boost/thread.hpp>
int main() {
boost::thread t1([] {
// ...
});
boost::thread t2([] {
// ...
});
t1.join();
t2.join();
}#include <iostream>
#include <omp.h>
int main() {
int n = 10000000;
int sum = 0;
#pragma omp parallel for reduction(+:sum)
for (int i = 0; i < n; i++) {
sum += i;
}
std::cout << "Sum: " << sum << std::endl;
}#include <iostream>
#include <termios.h>
#include <wiringPi.h>
int main() {
wiringPiSetup();
pinMode(0, INPUT);
while (true) {
int value = digitalRead(0);
std::cout << "Button state: " << value << std::endl;
}
}#include <iostream>
#include <emscripten/emscripten.h>
void main_loop() {
// ...
}
int main() {
emscripten_set_main_loop(main_loop, 0, 0);
return 0;
}fn main() {
println!("Hello, world!");
}package main
import "fmt"
func main() {
fmt.Println("Hello, world!")
}console.log("Hello, world!");print("Hello, world!")public class Main {
public static void main(String[] args) {
System.out.println("Hello, world!");
}
}public class Program {
public static void Main(string[] args) {
Console.WriteLine("Hello, world!");
}
}<?php
echo "Hello, world!";
?>puts "Hello, world!"echo "Hello, world!"