online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code   
Language
#include <iostream> #include<sstream> #include<string> #include<vector> #include<fstream> //this class represents a single vertex which is made up of two point x and y class Vertex { int x = 0; int y = 0; public: //parameterized constructor for initializing x and y Vertex(int px, int py): x(px), y(py) { } //display Vertex void printVertex() const { std::cout<<x <<" "<<y<<" "; } }; //this class represents a line segment which is made up of multiple vertices struct Line { std::string lineName; //this describes which line it is std::vector<Vertex> vertices; //this is a collection of all the vertex that this particular line is made up of }; int main() { std::string lineString; int pointX = 0, pointY = 0; std::ifstream inputFile("input.txt"); //a collection of all the Lines std::vector<Line> lines; if(inputFile) { //go line by line while(std::getline(inputFile, lineString)) { std::istringstream ss(lineString); //create a Line object Line currentLine; //read the first string specifying which line is this ss >> currentLine.lineName; //go number by number while(ss >> pointX >> pointY) { //add vertex to vector vertices currentLine.vertices.emplace_back(pointX, pointY); } //add this currentLine to lines lines.emplace_back(currentLine); } } else { std::cout<<"file cannot be opened"<<std::endl; } //lets confirm that we have all the lines correctly stored for(const Line& line: lines) { std::cout<<line.lineName<<": "; for(const Vertex& vertex: line.vertices) { vertex.printVertex(); } std::cout<<std::endl; } }
lineone 1 1 2 2 3 3 4 4 linetwo 1 1 2 2 3 3 linethree 1 1 5 5

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