-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
V for CPP developers
Alexander Medvednikov edited this page Apr 12, 2022
·
14 revisions
| Hello World | |
#include <iostream>
int main() {
std::cout << "Hello World!" << "\n";
}
|
fn main() {
println('Hello World!')
}
|
| Vector initialization | |
std::vector<int> numbers = {1, 2, 3, 4};
|
numbers := [1, 2, 3, 4] |
| Add an element to a vector | |
numbers.push_back(5); |
numbers << 5 |
| Printing a vector | |
std::copy(numbers.begin(), numbers.end(),
std::ostream_iterator(std::cout, " "));
std::cout << '\n';
|
println(numbers) |
| Filtering a vector | |
std::copy_if(numbers.begin(), numbers.end(),
std::back_inserter(bar),
[](int i){ return i % 2 == 0; });
|
numbers.filter(it % 2 == 0) |
| Reading a file | |
#include <iostream>
#include <fstream>
std::ifstream f("path");
std::string text;
text.assign(std::istreambuf_iterator(f), {});
if (!f)
std::cerr << "error reading from file\n";
|
import os
text := os.read_file(path) or {
eprintln(err)
}
|