Skip to content

V for Cpp developers

Alexander Medvednikov edited this page Nov 25, 2019 · 1 revision
Hello World
#include <iostream>
int main() {
  std::cout << "Hello World!" << std::endl;
  return 0;
}
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<char>(
    std::cout, " "));
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;
std::string text;
f.exceptions(std::ifstream::failbit |
  std::ifstream::badbit);
try {
  f.open(path);
  text.assign(std::istreambuf_iterator(f),
    std::istreambuf_iterator());
} catch (std::system_error& e) {
  std::cerr << e.code().message() <<
    std::endl;
}
import os
text := os.read_file(path)or{
  eprintln(err)
}
You can’t perform that action at this time.