online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code   
Language
/****************************************************************************** Online C++ Compiler. Code, Compile, Run and Debug C++ program online. Write your code in this editor and press "Run" button to compile and execute it. *******************************************************************************/ #include <iostream> #include <vector> using namespace std; template<typename T> T average(const std::vector<T> &vec) { if(vec.empty()) { throw std::runtime_error("Vector passed is empty");//throw if the vector is empty because we don't want to operate on an empty vector } T sum{}; for(T elem: vec) { sum += elem; } return sum/vec.size(); } int main() { std::vector<float> myvec1{1,2,3.4}; std::cout<<"average is: "<<average(myvec1); std::vector<int> myvec2; average(myvec2);//this will print "vector passed is empty" return 0; }

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue