1234567891011
#include <iostream> #include "ponto.h" using namespace std; int main(){ Ponto a, b; a.set(0,0); b.read(); cout << a.view() << endl; cout << b.view() << endl; }
1234567891011121314151617181920212223
#ifndef PONTO_H #define PONTO_H #include <iostream> #include <cstring> class Ponto{ private: int x, y; public: void read(){ std::cout << "x = "; std::cin >> x; std::cout << "y = "; std::cin >> y; } char *view(){ char *output; strcpy(output, "lixo"); return (output); } void set(int a, int b){ x=a; y=b; } }; #endif
12345
char* view() { char* output; // UNINITIALIZED strcpy( output, "lixo" ); // Copy the string "lixo" to a random memory location return output; }
12345678910111213141516171819202122232425262728
#ifndef PONTO_H #define PONTO_H #include <iostream> #include <string> #include <sstream> using namespace std; class Ponto{ private: int x, y; string build_output; stringstream sx, sy; public: void read(){ cout << "x = "; cin >> x; cout << "y = "; cin >> y; } string view(){ sx << x; sy << y; build_output =(string)"("+sx.str()+(string)","+sy.str()+(string)")"; return (build_output); } void set(int a, int b){ x=a; y=b; } }; #endif
(string)"("+sx.str()+","+sy.str()+")"
build_output ="("+","+")";
build_output =(string)"("+","+")";
build_output = "(,)";