C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 27th, 2009, 10:52 PM
jakotheshadows's Avatar
jakotheshadows jakotheshadows is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2009
Posts: 149 jakotheshadows User rank is Sergeant Major (2000 - 5000 Reputation Level)jakotheshadows User rank is Sergeant Major (2000 - 5000 Reputation Level)jakotheshadows User rank is Sergeant Major (2000 - 5000 Reputation Level)jakotheshadows User rank is Sergeant Major (2000 - 5000 Reputation Level)jakotheshadows User rank is Sergeant Major (2000 - 5000 Reputation Level)jakotheshadows User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 12 h 1 m 16 sec
Reputation Power: 35
Binary '<<' : no operator found which takes a right-hand operand of type 'dateNode'

Hello, my name is Anthony and I am having some difficulty with a class project. Firstly, my code:

(date.cpp)
PHP Code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

#include "DateNode.h";
bool text(string fName);
ostreamoperator<<(const dateNode dostreamout);


void main()
string fName "C:\Users\Anthony\Documents\Visual Studio 2008\Projects\DateNode.cpp\Dates.txt";
  
fstream dateText;
  
int dateSize 1;
  class 
dateNode date[20];
  
  if(
text(fName))
    
dateText.open(fName.data(), ios::in);
  
  while(!
dateText.eof())
    { if(
date[dateSize].get(cindateText))
        
dateSize++;
    };

  
dateText.close();

  for(
int i 1i<=dateSizei++)
    
cout << date[i] << endl;
}

bool text(string fName)
fstream outFile;
  
outFile.open(fName.data(), ios::out);
  
  if(
outFile.is_open())
    { 
outFile << "Sep. 17, 1987" << endl//1 
      
outFile << "Jan. 6, 2001" << endl;  //2
      
outFile << "Mar. 4, 1990" << endl;  //3
      
outFile << "Jun. 16, 1993" << endl//4
      
outFile << "Jul. 5, 1996" << endl;  //5
      
outFile << "Nov. 11, 2004" << endl//6
      
outFile << "Feb. 20, 2007" << endl//7
      
outFile << "Sep. 3, 2009" << endl;  //8
      
outFile.close();
    };

  return 
outFile.good();
}

ostreamoperator<<(const dateNodedostreamout)
{ return 
out<<d.getMonthName()<<" "<<d.getDay()<<" "<<d.getYear();



(DateNode.h)
PHP Code:
//DateNode class definition

class dateNode
{ public:
        
dateNode();
    
bool get(istream &infstream);
    
int getYear() const { return year; }
    
int getMonthNum() const { return monthNum; }
    
int getDay() const { return day; }
    
string getMonthName() const { return monthName; }
  private:
        
string monthName;
    
int dayyearmonthNum;
}; 


(DateNode.cpp)
PHP Code:
#include <iostream>
#include <string>
#include <fstream>
using namespace std;

#include "DateNode.h";

// Null Constructor

dateNode::dateNode()
day 0;
  
monthNum 0;
  
year 0;
  
monthName "Empty";
}

// Retrieve Text Data

bool dateNode::get(istream &infstream text)
text >> monthName;
   
text >> day;
   
text >> year;
   return 
text.good();



I am only getting one error, along with several warnings, (using MS Visual C++) but the error as stated by the compiler is:
1>c:\users\anthony\documents\visual studio 2008\projects\datenode.cpp\datenode\date.cpp(28) : error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'dateNode' (or there is no acceptable conversion)

The purpose of this program (at least thus far) is to create a text file called dates.txt and put 8 different dates into it. Then, it should open the file and read and store the dates in a dateNode array named date. I am supposed to overload the << operator so that I can use the following snippet of code:
PHP Code:
for(int i 1i<=dateSizei++)
    
cout << date[i] << endl

to display the dates. I believe my problem lies somewhere within either my use, definition, or declaration of the overloaded operator, but I do not understand what I am doing wrong. Thanks in advance for any advice.

Reply With Quote
  #2  
Old August 27th, 2009, 11:21 PM
sizablegrin's Avatar
sizablegrin sizablegrin is offline
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Jun 2005
Posts: 5,964 sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 3 Weeks 2 Days 12 h 47 m 19 sec
Warnings Level: 10
Number of bans: 1
Reputation Power: 4850
You need to read the "How to Post" thread. It's the one that says, "READ THIS FIRST." Sounds silly, I know, but your code is too dam' ugly to waste time on.

If you can't read and comprehend that, then you don't need to be farbling with a programming language.

Just sayin'.
__________________
Write no code whose complexity leaves you wondering what the hell you did.
Politically Incorrect DaWei on Pointers Grumpy on Exceptions

Reply With Quote
  #3  
Old August 27th, 2009, 11:24 PM
jakotheshadows's Avatar
jakotheshadows jakotheshadows is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2009
Posts: 149 jakotheshadows User rank is Sergeant Major (2000 - 5000 Reputation Level)jakotheshadows User rank is Sergeant Major (2000 - 5000 Reputation Level)jakotheshadows User rank is Sergeant Major (2000 - 5000 Reputation Level)jakotheshadows User rank is Sergeant Major (2000 - 5000 Reputation Level)jakotheshadows User rank is Sergeant Major (2000 - 5000 Reputation Level)jakotheshadows User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 12 h 1 m 16 sec
Reputation Power: 35
You're right sizablegrin, I will try and fix it up. Sorry about that.

Reply With Quote
  #4  
Old August 27th, 2009, 11:32 PM
jakotheshadows's Avatar
jakotheshadows jakotheshadows is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2009
Posts: 149 jakotheshadows User rank is Sergeant Major (2000 - 5000 Reputation Level)jakotheshadows User rank is Sergeant Major (2000 - 5000 Reputation Level)jakotheshadows User rank is Sergeant Major (2000 - 5000 Reputation Level)jakotheshadows User rank is Sergeant Major (2000 - 5000 Reputation Level)jakotheshadows User rank is Sergeant Major (2000 - 5000 Reputation Level)jakotheshadows User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 12 h 1 m 16 sec
Reputation Power: 35
Is that better? Anything else wrong with my post that I should be aware of? Any advice on my posting or my code is greatly appreciated.

Reply With Quote
  #5  
Old August 28th, 2009, 03:29 AM
clifford's Avatar
clifford clifford is offline
Contributing User
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Aug 2003
Location: UK
Posts: 4,807 clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 2 Days 17 h 20 m 11 sec
Reputation Power: 1800
The overload protoyype should be:

Code:
ostream& operator<<( ostream& out, const dateNode d); 


you have the arguments the wrong way around. Think about it, in teh expression cout << data, the iostream object is on the left-and side.

BTW regard warnings as errors if you want to be a good software developer. You probably should have posted those too. You can configure the compiler to reject code that has warnings, and increase the warning level; I suggest that you do both.

Clifford

Reply With Quote
  #6  
Old August 28th, 2009, 01:11 PM
jakotheshadows's Avatar
jakotheshadows jakotheshadows is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2009
Posts: 149 jakotheshadows User rank is Sergeant Major (2000 - 5000 Reputation Level)jakotheshadows User rank is Sergeant Major (2000 - 5000 Reputation Level)jakotheshadows User rank is Sergeant Major (2000 - 5000 Reputation Level)jakotheshadows User rank is Sergeant Major (2000 - 5000 Reputation Level)jakotheshadows User rank is Sergeant Major (2000 - 5000 Reputation Level)jakotheshadows User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 12 h 1 m 16 sec
Reputation Power: 35
changed
PHP Code:
 ostreamoperator<<(const dateNode dostreamout); 

to
PHP Code:
 ostreamoperator <<(ostreamout, const dateNoded); 


and I changed
PHP Code:
 ostreamoperator<<(const dateNodedostreamout)
{ return 
out<<d.getMonthName()<<" "<<d.getDay()<<" "<<d.getYear();


to
PHP Code:
 ostreamoperator<<(ostreamout, const dateNoded)
{ return 
out<<d.getMonthName()<<" "<<d.getDay()<<" "<<d.getYear();



and upon attempt to compile I get the following warnings and errors:
1>c:\users\anthony\documents\visual studio 2008\projects\datenode.cpp\datenode\date.cpp(6) : warning C4067: unexpected tokens following preprocessor directive - expected a newline
1>c:\users\anthony\documents\visual studio 2008\projects\datenode.cpp\datenode\date.cpp(12) : warning C4129: 'A' : unrecognized character escape sequence
1>c:\users\anthony\documents\visual studio 2008\projects\datenode.cpp\datenode\date.cpp(12) : warning C4129: 'D' : unrecognized character escape sequence
1>c:\users\anthony\documents\visual studio 2008\projects\datenode.cpp\datenode\date.cpp(12) : warning C4129: 'V' : unrecognized character escape sequence
1>c:\users\anthony\documents\visual studio 2008\projects\datenode.cpp\datenode\date.cpp(12) : warning C4129: 'P' : unrecognized character escape sequence
1>c:\users\anthony\documents\visual studio 2008\projects\datenode.cpp\datenode\date.cpp(12) : warning C4129: 'D' : unrecognized character escape sequence
1>c:\users\anthony\documents\visual studio 2008\projects\datenode.cpp\datenode\date.cpp(12) : warning C4129: 'D' : unrecognized character escape sequence
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\fstream(934) : error C2248: 'std::basic_ios<_Elem,_Traits>::basic_ios' : cannot access private member declared in class 'std::basic_ios<_Elem,_Traits>'

I think the error has something to do with the fstream library (since it says fstream in it) but all I can guess at is that somehow my fstream object isn't interacting with my class properly? I have no idea what the warnings mean. Completely confused on those.

Reply With Quote
  #7  
Old August 28th, 2009, 01:36 PM
mitakeet's Avatar
mitakeet mitakeet is offline
I'm Baaaaaaack!
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Jul 2003
Location: Maryland
Posts: 5,538 mitakeet User rank is Captain (20000 - 30000 Reputation Level)mitakeet User rank is Captain (20000 - 30000 Reputation Level)mitakeet User rank is Captain (20000 - 30000 Reputation Level)mitakeet User rank is Captain (20000 - 30000 Reputation Level)mitakeet User rank is Captain (20000 - 30000 Reputation Level)mitakeet User rank is Captain (20000 - 30000 Reputation Level)mitakeet User rank is Captain (20000 - 30000 Reputation Level)mitakeet User rank is Captain (20000 - 30000 Reputation Level)mitakeet User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Weeks 4 Days 2 h 38 m 46 sec
Reputation Power: 242
You have an unclosed quote somewhere, based on my experience looking at these sorts of things. In your case the absolutely are not warnings, they are errors.

If you colorize your code (which you can do here, just use php code tags and look in the preview) you will likely immediately know where the fault is.
__________________

My blog, The Fount of Useless Information http://sol-biotech.com/wordpress/
Free code: http://sol-biotech.com/code/.
Secure Programming: http://sol-biotech.com/code/SecProgFAQ.html.
Performance Programming: http://sol-biotech.com/code/PerformanceProgramming.html.
LinkedIn Profile: http://www.linkedin.com/in/keithoxenrider

It is not that old programmers are any smarter or code better, it is just that they have made the same stupid mistake so many times that it is second nature to fix it.
--Me, I just made it up

The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man.
--George Bernard Shaw

Reply With Quote
  #8  
Old August 28th, 2009, 01:38 PM
clifford's Avatar
clifford clifford is offline
Contributing User
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Aug 2003
Location: UK
Posts: 4,807 clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 2 Days 17 h 20 m 11 sec
Reputation Power: 1800
The errors mean exactly what they say. Did you actually read them!?

#include "DateNode.h";

What is that ';' doing there?

\ is the esacpe sequence introducer, as in '\n' for newline for example. To include a '\' in a string, the escap sequence '\\' must be used.

This is what I mean about warnings; these are errors. The compiler is saying "I can compile this, but it is unlikely to be what you intended".

Also never look at the last message! Fix the ones before it first, the chances are the later ones are related and will go away. Now think about it; what ar ethe chances of tehre being an error in a standard library header? About nil I'd say.

Fix the warnings, report back (and post the modified code if you need further assistance).

Clifford.

Reply With Quote
  #9  
Old August 29th, 2009, 01:35 AM
jakotheshadows's Avatar
jakotheshadows jakotheshadows is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2009
Posts: 149 jakotheshadows User rank is Sergeant Major (2000 - 5000 Reputation Level)jakotheshadows User rank is Sergeant Major (2000 - 5000 Reputation Level)jakotheshadows User rank is Sergeant Major (2000 - 5000 Reputation Level)jakotheshadows User rank is Sergeant Major (2000 - 5000 Reputation Level)jakotheshadows User rank is Sergeant Major (2000 - 5000 Reputation Level)jakotheshadows User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 12 h 1 m 16 sec
Reputation Power: 35
changed
PHP Code:
#include "DateNode.h"; 

to
PHP Code:
#include "DateNode.h" 

in both Date.cpp and DateNode.cpp

changed
PHP Code:
 string fName "C:\Users\Anthony\Documents\Visual Studio 2008\Projects\DateNode.cpp\Dates.txt"

to
PHP Code:
 string fName "C:\\Users\\Anthony\\Documents\\Visual Studio 2008\\Projects\\DateNode.cpp\\Dates.txt"

in Date.cpp

Those fixes actually did get rid of all of the warnings. However, the error message:
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\fstream(934) : error C2248: 'std::basic_ios<_Elem,_Traits>::basic_ios' : cannot access private member declared in class 'std::basic_ios<_Elem,_Traits>'
still plagues me when I try to compile this code.

Reply With Quote
  #10  
Old August 29th, 2009, 04:17 AM
clifford's Avatar
clifford clifford is offline
Contributing User
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Aug 2003
Location: UK
Posts: 4,807 clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 2 Days 17 h 20 m 11 sec
Reputation Power: 1800
Quote:
Originally Posted by jakotheshadows
Those fixes actually did get rid of all of the warnings.

Good now at least you can see the wood for the trees, and more importantly know that you are not wasting your time analysing this message.

fstream::data() is a private member function of the std::ios base class. Where did you get the idea you could call that since it is implementation dependent and undocumented!? You need fName.c_str() to obtain a const char* required by fstream::open(). Or simply declare fName to be a const char* in the first instance since.

The error message is somewhat arcane, and it would have helped if it has included the name of the private member that was being accessed, or indicated where the offending call was being made from. These are things that yopu would get from say GCC. Sometimes when a compiler message really stumps me I compile it in a different compiler (usually GCC and VC++). The different approaches to error mesaging sometimes shed light on the problem. In this case I did not do that, I started out with Occam's razor which suggests the standard header file is correct, so then I looked to see where fstream objects were used in the code being compiled and checked those lines, and the call to a function not documented as a member function stuck out prominently.

Luckily I spotted have the error without you posting the modified code I asked for :rolleyes:. I had intended to use it to attempt to reproduce your error. I would not have bothered to laboriously reproduce it by applying your incremental changes.

Clifford

Last edited by clifford : August 29th, 2009 at 05:42 AM.

Reply With Quote
  #11  
Old August 30th, 2009, 02:11 PM
jakotheshadows's Avatar
jakotheshadows jakotheshadows is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2009
Posts: 149 jakotheshadows User rank is Sergeant Major (2000 - 5000 Reputation Level)jakotheshadows User rank is Sergeant Major (2000 - 5000 Reputation Level)jakotheshadows User rank is Sergeant Major (2000 - 5000 Reputation Level)jakotheshadows User rank is Sergeant Major (2000 - 5000 Reputation Level)jakotheshadows User rank is Sergeant Major (2000 - 5000 Reputation Level)jakotheshadows User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 12 h 1 m 16 sec
Reputation Power: 35
Here is my complete modified code thus far:

(DateNode.h)
PHP Code:
//DateNode class definition

class dateNode
{ public:
    
dateNode();
    
bool get(istream &infstream);
    
int getYear() const { return year; }
    
int getMonthNum() const { return monthNum; }
    
int getDay() const { return day; }
    
string getMonthName() const { return monthName; }
  private:
    
string monthName;
    
int dayyearmonthNum;
}; 


(DateNode.cpp)
PHP Code:
#include <iostream>
#include <string>
#include <fstream>
using namespace std;

#include "DateNode.h"

// Null Constructor

dateNode::dateNode()
day 0;
  
monthNum 0;
  
year 0;
  
monthName "Empty";
}

// Retrieve Text Data

bool dateNode::get(istreaminfstream text)
text >> monthName;
  
text >> day;
  
text >> year;
  return 
text.good();



(Date.cpp)
PHP Code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

#include "DateNode.h"
bool text(fstreamf);
ostreamoperator <<(ostreamout, const dateNode d);

void main()
fstream dateText;
  
int dateSize 1;
  class 
dateNode date[20];
 
  if(
text(dateText))
      
dateText.open("dates.txt"fstream::in);
  
  while(!
dateText.eof())
    { if(
date[dateSize].get(cindateText))
        
dateSize++;
    };

  
dateText.close();

  for(
int i 1i<=dateSizei++)
    
cout << date[i] << endl;
}

bool text(fstreamf)
f.open("dates.txt"fstream::out);
  
  if(
f.is_open())
    { 
<< "Sep. 17, 1987" << endl//1 
      
<< "Jan. 6, 2001" << endl;  //2
      
<< "Mar. 4, 1990" << endl;  //3
      
<< "Jun. 16, 1993" << endl//4
      
<< "Jul. 5, 1996" << endl;  //5
      
<< "Nov. 11, 2004" << endl//6
      
<< "Feb. 20, 2007" << endl//7
      
<< "Sep. 3, 2009" << endl;  //8
    
};

  if(
f.good()&&f.is_open())
    { 
f.close();
      return 
true;
    }
  else
    return 
false;
}

ostreamoperator<<(ostreamout, const dateNode d)
{ return 
out<<d.getMonthName()<<" "<<d.getDay()<<" "<<d.getYear();



all of this still gives me the same error I mentioned most recently.
I tried your advice with changing fName to a const char* with the following version of Date.cpp:

PHP Code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

#include "DateNode.h"
bool text(const charf);
ostreamoperator <<(ostreamout, const dateNode d);

void main()
fstream dateText;
  
int dateSize 1;
  class 
dateNode date[20];
  const 
charfName "C:\\Users\\Anthony\\Documents\\Visual Studio 2008\\Projects\\DateNode.cpp\\Dates.txt";
 
  if(
text(fName))
      
dateText.open(fName.data(), ios::in);
  
  if(
dateText.is_open())
    { while(!
dateText.eof())
      { if(
date[dateSize].get(cindateText))
        
dateSize++;
      };
    };

  
dateText.close();

  for(
int i 1i<=dateSizei++)
    
cout << date[i] << endl;
}

bool text(const charf)
fstream out;
    
  
out.open(f.data(), ios::out);
  
  if(
out.is_open())
    { 
out << "Sep. 17, 1987" << endl//1 
      
out << "Jan. 6, 2001" << endl;  //2
      
out << "Mar. 4, 1990" << endl;  //3
      
out << "Jun. 16, 1993" << endl//4
      
out << "Jul. 5, 1996" << endl;  //5
      
out << "Nov. 11, 2004" << endl//6
      
out << "Feb. 20, 2007" << endl//7
      
out << "Sep. 3, 2009" << endl;  //8
    
};

  if(
out.good()&&out.is_open())
    { 
out.close();
      return 
true;
    }
  else
    return 
false;
}

ostreamoperator<<(ostreamout, const dateNode d)
{ return 
out<<d.getMonthName()<<" "<<d.getDay()<<" "<<d.getYear();



but that gives me these two errors:
1>c:\users\anthony\documents\visual studio 2008\projects\datenode.cpp\datenode\date.cpp(17) : error C2228: left of '.data' must have class/struct/union
1> type is 'const char *'
1>c:\users\anthony\documents\visual studio 2008\projects\datenode.cpp\datenode\date.cpp(35) : error C2228: left of '.data' must have class/struct/union
1> type is 'const char *'

I'm such a n00b

Reply With Quote
  #12  
Old August 30th, 2009, 02:20 PM
mitakeet's Avatar
mitakeet mitakeet is offline
I'm Baaaaaaack!
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Jul 2003
Location: Maryland
Posts: 5,538 mitakeet User rank is Captain (20000 - 30000 Reputation Level)mitakeet User rank is Captain (20000 - 30000 Reputation Level)mitakeet User rank is Captain (20000 - 30000 Reputation Level)mitakeet User rank is Captain (20000 - 30000 Reputation Level)mitakeet User rank is Captain (20000 - 30000 Reputation Level)mitakeet User rank is Captain (20000 - 30000 Reputation Level)mitakeet User rank is Captain (20000 - 30000 Reputation Level)mitakeet User rank is Captain (20000 - 30000 Reputation Level)mitakeet User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Weeks 4 Days 2 h 38 m 46 sec
Reputation Power: 242
I have no idea what the heck "if(text(fName))" is supposed to do, but I can tell you with 100% certainty that "dateText.open(fName.data(), ios::in);" isn't doing anything you want it to do. Do some research on the capabilities of char, pointers to char (char *) and what happens when you make one const. Then look around for the documentation on the .data() method and report back here with what you learned.

By the by, if I simply tell you what you need to know you really aren't learning how to learn. You have made some critical mistakes and I am trying to help you learn what they are.

You might also want to read up on RTFM a bit also as that will become critical if you choose to continue as a programmer (in C++ or any other language).

Reply With Quote
  #13  
Old August 30th, 2009, 05:20 PM
clifford's Avatar
clifford clifford is offline
Contributing User
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Aug 2003
Location: UK
Posts: 4,807 clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 2 Days 17 h 20 m 11 sec
Reputation Power: 1800
The code you posted still includes the error I have already told you about, except this time you have changed the type of fName so that it is no longer a class, so attempting to call a member function of fName is now nonsense. I would have thought that "left of '.data' must have class/struct/union" was a pretty big clue - "left of .data" being fName.

If you change fName to a const char* as I suggested, is it not obvious also that fName.data() no longer makes even less sense than it did before!? You just need fName there.

I believe I have already suggested that you actually read the error messages. This feels like spoon feeding. This is not the quick easy method of getting your work done that you might be thinking. Actually thinking would be far quicker.

Clifford

Reply With Quote
  #14  
Old September 1st, 2009, 12:40 AM
jakotheshadows's Avatar
jakotheshadows jakotheshadows is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2009
Posts: 149 jakotheshadows User rank is Sergeant Major (2000 - 5000 Reputation Level)jakotheshadows User rank is Sergeant Major (2000 - 5000 Reputation Level)jakotheshadows User rank is Sergeant Major (2000 - 5000 Reputation Level)jakotheshadows User rank is Sergeant Major (2000 - 5000 Reputation Level)jakotheshadows User rank is Sergeant Major (2000 - 5000 Reputation Level)jakotheshadows User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 12 h 1 m 16 sec
Reputation Power: 35
OK! I've got some code that compiles now, but it crashes as soon as I try to run it. I know you are all trying to encourage me to think more about my own code instead of coming here, and I do appreciate it, but now I have no compiler errors to work with. I'm just stuck staring at my code until I see whats making it crash. I'm using Vista 64 if that means anything.. Here is the code I have now:

DateNode.cpp
PHP Code:
#include <iostream>
#include <string>
#include <fstream>
using namespace std;

#include "DateNode.h"

// Null Constructor

dateNode::dateNode()
day 0;
  
monthNum 0;
  
year 0;
  
monthName "Empty";
}

void dateNode::setDay(int d)
day d;
}

void dateNode::setYear(int y)
year y;
}

void dateNode::setMonthNum(int n)
monthNum n;
}

void dateNode::setMonthNam(string s)
monthName s;



DateNode.h
PHP Code:
//DateNode class definition

class dateNode
{ public:
    
dateNode();
    
int getYear() const { return year; }
    
int getMonthNum() const { return monthNum; }
    
int getDay() const { return day; }
    
string getMonthName() const { return monthName; }
    
void setYear(int);
    
void setDay(int);
    
void setMonthNum(int);
    
void setMonthNam(string);
  private:
    
string monthName;
    
int dayyearmonthNum;
}; 


date.cpp
PHP Code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

#include "DateNode.h"
bool text();
ostreamoperator <<(ostreamout, const dateNode d);

void main()
ifstream dateText;
  
int dateSize 1;
  class 
dateNode date[20];
  
bool good;
  
string textMonth;
  
int textDaytextYear;
  
  
good text();
 
  if(
good)
    
dateText.open("dates.txt");
  
  if(
dateText.is_open())
    { while(!
dateText.eof())
      { 
dateText >> textMonth;
        
dateText >> textDay;
        
dateText >> textYear;
        
date[dateSize].setMonthNam(textMonth);
        
date[dateSize].setDay(textDay);
        
date[dateSize].setYear(textYear);
        
dateSize++;
      };
    };

  
dateText.close();

  for(
int i 1i<=dateSizei++)
    
cout << date[i] << endl;
}

bool text()
ofstream out;
    
  
out.open("dates.txt");
  
  if(
out.is_open())
    { 
out << "Sep. 17, 1987" << endl//1 
      
out << "Jan. 6, 2001" << endl;  //2
      
out << "Mar. 4, 1990" << endl;  //3
      
out << "Jun. 16, 1993" << endl//4
      
out << "Jul. 5, 1996" << endl;  //5
      
out << "Nov. 11, 2004" << endl//6
      
out << "Feb. 20, 2007" << endl//7
      
out << "Sep. 3, 2009" << endl;  //8
    
};

  if(
out.good()&&out.is_open())
    { 
out.close();
      return 
true;
    }
  else
    return 
false;
}

ostreamoperator<<(ostreamout, const dateNode d)
{ return 
out<<d.getMonthName()<<" "<<d.getDay()<<" "<<d.getYear();



Please help

Reply With Quote
  #15  
Old September 1st, 2009, 01:38 AM
sizablegrin's Avatar
sizablegrin sizablegrin is offline
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Jun 2005
Posts: 5,964 sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 58th Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 3 Weeks 2 Days 12 h 47 m 19 sec
Warnings Level: 10
Number of bans: 1
Reputation Power: 4850
Where is it failing? Don't you have a debugger? Why don't you learn to use it? It repays the effort many times over.

Why would you name a variable "good" when you know you have a method named "good." Not the same, but don't you think you're confusing issues when you should be simplifying?

Just curious.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Binary '<<' : no operator found which takes a right-hand operand of type 'dateNode'

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap