Hi, I have made a class and have an overloaded ostream operator method in it... However it tells me: "overloaded 'operator<<' must be a binary operator (has 3 parameters)." Can someone tell me how to fix this? Thank you! I have included some of my code: class Element { private: list<Element*> _children; char* _tag; int _value; public: ostream& operator<<(ostream& out, const Element& E); // (preordered traversal) }

Member Avatar
Member Avatar
+0 forum 4

Hi, I've been learning about the std::copy function in the <algorithm> header and I'm stuck on this exercise that I gave my self. Let's see the code snippet first: #include <iostream> #include <vector> #include <algorithm> #include <iterator> using namespace std; ostream& operator<<(ostream& os, const int p_val) { os.put( p_val*2); return os; } int main(/*const int argc,const char* const argv[]*/) { std::vector<int> myVector = {34,54,43,2,7,87}; std::copy(myVector.begin(), myVector.end(), ostream_iterator<int>(std::cout, " ")); cin.get(); return 0; } Basically what I'm trying to achieve is: I have a vector full of integers. I want to print the mutiply of 2 of these integers to std::cout …

Member Avatar
Member Avatar
+0 forum 2

Hi again! So, I have an object that gets appended to a linked list now. Now I need to have all of that item's data output in a formatted manner - something similar to this: CD Artist CD Title CD Length Track Name Track Length Arist name here Title here hh:mm:ss Track name here mm:ss Track name here mm:ss Track name here mm:ss The problem with this is that the output for this is all in the overloaded << operator for my CD object and I'm having trouble figuring out how to append the track names and track lenghts, which …

Member Avatar
Member Avatar
+0 forum 6

Hi all and thanks in advance for your help ! I have a very simple class called circle and i wanna add the ostream << so i can have the ability in main to write cout<<a<<b<<c; the theme is i'm getting many compile errors in the same row eg iso c++ forbids the declaration of ostream with no type here's the code circle.h #ifndef CIRCLE_H #define CIRCLE_H class Circle { private : float radius; public: Circle(); Circle(float r); float getarea(); float getperimeter(); friend ostream &operator(ostream &mystream,Circle &c); }; #endif circle.cpp #define PI 3.14159 #include "circle.h" using namespace std; Circle::Circle() { …

Member Avatar
Member Avatar
+0 forum 3

Hey guys, i am a beginner in c++ and i don't know what's wrong with my code. i'dont get any errors, but when i run the programme the following: "... Line: 251 Expression: vector iterators incompatible ..." I think there is a problem with "b.getmark()" and "b.getcoursename()" but i don't know how to solve it since i cannot use "coursename" or "mark" instead Thanks in advance, guys. I hope someone can help me! My code looks a little bit strange cos some parts are not displayed properly... strangely the problematic parts. Sorry about that. This is my code: #include <iostream> …

Member Avatar
Member Avatar
+0 forum 5

Hello all. I am having difficulty getting my program to output data correctly. I have a class member function that is supposed to return the value of a specific member of a struct element based on identification with its (the struct element's) other members. [code] float MatrixType::valueAt(int i, int j) const { // code to return the float value at // significant location row i col j if(i == matrix[length].row && j == matrix[length].col) return matrix[length].value; // checks to match up row and col to find correct value else return 0.0; } // end accessor valueAt[/CODE] The matrix[] array is …

Member Avatar
Member Avatar
+0 forum 6

hello my dear friends I have read a book that was simple to learn c++,recently But in operator ovorloading threads ,I dont underestand many example for ovoreloading in another books & booklets for example : in the example below 1 // Fig. 11.3: PhoneNumber.h 2 // PhoneNumber class definition 3 #ifndef PHONENUMBER_H 4 #define PHONENUMBER_H 5 6 #include <iostream> 7 using std::ostream; 8 using std::istream; 9 10 #include <string> 11 using std::string; 12 13 class PhoneNumber 14 { 15 friend ostream &operator<<( ostream &, const PhoneNumber & ); 16 friend istream &operator>>( istream &, PhoneNumber & ); 17 private: 18 …

Member Avatar
Member Avatar
+0 forum 2

I've to make several experiments of some algorithms. I want to send those results to a .txt file [CODE] //.... for (count= 1; count<= 20; count++){ //.... std::cout<<exp<<"Time: "<<duration << " seconds" <<'\n'; ofstream f2; f2.open("results.txt", ofstream::out); for(int i=0; i<=20; i++){ f2<<duration<<endl; } f2.close(); } [/CODE] With this code, I only get the same result repeated several times, instead of saving a result per line. What do I need to modify of this code??

Member Avatar
Member Avatar
+0 forum 3

Hi all, I am trying to create a class to serve as a customized cout class. Right now I have made some test code to see if I can do it. Right now I am trying to make it function just like cout, but later I will have it do more than just print text to the screen. Currently my class works when I try and print one item, but not multiple ones. The code: [CODE=c++, operator.cpp]#include "operator.h" using namespace std; void printclass::operator<<( const string & mesg ) { cout << mesg; } int main() { printclass print; print << …

Member Avatar
Member Avatar
+0 forum 2

Hey, so i've looked around online for a bit, and after finding similar, but not exact (as in it doesn't help me), i'm gonna post my problem here :P. I'm working on a class to handle Complex numbers. This is going to require a lot of operator overloads and the sort to handle the different operations i need to test. Well one of the things that i need to do is be able to use the << and >> operators to input/output data so things are read/shown properly. My header file is below: [CODE] // ******************************************************** // Complex.h // // …

Member Avatar
Member Avatar
+0 forum 4

The End.