it is really frustating to handle your systems setup, especially if you want to start to learn coding.
My rescue called: build system. I'm using cmake with this tutorial.
But first thing first, for your special question, what you'll need are following workspace:
working_directory
|--build/
|--src/test_code.cpp
|--src/CMakeLists.txt
with your code (I name it test_code.cpp
):
#include<iostream>
#include<string>
int main()
{
std::string a="world";
std::cout<<a;
return 0;
}
and CMakeLists.txt
:
cmake_minimum_required (VERSION 3.7)
project(testSomething)
add_executable(test test_code.cpp)
and run following in /build
directory:
> cmake ../src
> make
> ./test
Of course you'll need to install cmake first.
I think, directly using a build system in a tutorial helps you take care of your system setup, so usually those build system could find your installed compiler, linker etc. without you telling it explicitly. (So its a kind of vodoo magic :)).