c++ - Overloading >> operator and adding a number to a string -


I'm having trouble adding numbers to my function string, numbers are matrix and are integer. I am trying to parse them in a string formised in {{A, b, c}, {d, e, f}, {g, h, i}}. I have implemented the code but when I run it, it is empty where the number should be and why I do not know why.

My Function:

  Istream & amp; Operator & gt; & Gt; (Istream and In, Matrix and M) {Vector & lt; Int & gt; Vec; Vec = m.getRow (0); String matrix = "{"; In & gt; & Gt; Matrix; For (int i = 0; i & lt; vec.size (); i ++) {vector & lt; Int & gt; VecRow = m.getRow (i); Matrix + = "{"; For (int j = 0; j; lieu; vec.size (); j ++) {if (j> = vec.size () - 1) {matrix + = vicro [j]; } Else {matrix + = vecRow [j] + ","; }} VecRow.clear (); Matrix + = "}"; VecRow = m.getRow (i); } Matrix + = "}"; The court's & lt; & Lt; Matrix & lt; & Lt; Endl; in back; }  

OK, I have modified it and now I have not found any errors, but when I call this function in my tester (cin >> matric) then it is freeze Nothing happens after that.

When you call the surcharge operator & gt; & Gt; To get data from the global std :: cin stream, enter the parameter in the stream (std :: istream & amp; ; In, ...) / P>

Something like this to get you started:

  # include & lt; Iostream & gt; Structure matrix {}; Std :: IStream & amp; Operator & gt; & Gt; {Std :: istream & amp; matrix, and m} {// input format: {{a, b, c}, {d, e, f}, {g, h, i}} char c; // We hope that the first letter will be '{' if (GET (C)! = '{'}) .setset (std :: ios :: failbit); // signal error other {// now process of middle part: // {a, b, c}, {d, e, f}, {g, h, i} // ... // then check end Do brace '}' if (is.get (c)! = '}') Is.setstate (std :: ios :: failbit); // signal error} is return; }  

But it turns out that you are writing matrix in the opposite - output.

In this case you enter operator and const context in the context of your matrix .

(std :: ostream & amp; os, ...) type the parameter like this:

  std :: ostream & Amp; ; Operator & lt; & Lt; {Std :: ostream & os, const matrix and m} {// output format: {{a, b, c}, {d, e, f}, {g, h, i}} os & lt; & Lt; '{'; // initial brace // for each line (unsigned line = 0; line & lt; m.getSize (); ++ line) {const std :: vector & lt; Int & gt; & Amp; VecRow = m.getRow (line); // output one line {a, b, c} object here in the OS & lt; & Lt; '{'; // open line brace // loop on each row (unsigned i = 0; i  

Now that you have std :: cout & lt; & Lt; M; Your function will be called and refer to the parameter (std :: ostream & amp; os, ...) std :: cout .


Comments

Popular posts from this blog

HTML/CSS - Automatically set height width from background image? -

php - Mysql Show Process - Sleep Commands and what to do -

c - What is the address of buf (the local variable in the main function)? -