Welcome to Dream.In.Code
Become a C++ Expert!

Join 150,217 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,157 people online right now. Registration is fast and FREE... Join Now!




c++ String output Error please help asap

 
Reply to this topicStart new topic

c++ String output Error please help asap, *Solved BY MYSELF* No error Using .net, instead of 6.0

xxblackrain
19 Nov, 2007 - 10:33 PM
Post #1

New D.I.C Head
*

Joined: 19 Nov, 2007
Posts: 2


My Contributions
Hi, I'm having an error when trying to output a string to a file and basic output. error is as follows:
K:\C++2\Final Project\FactFinder\Birthday.cpp(530) : error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (or there is no ac
ceptable conversion)
K:\C++2\Final Project\FactFinder\Birthday.cpp(535) : error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (or there is no ac
ceptable conversion)


the program is rather lengthy so ill just paste the function and include statements.
CODE

#include "Birthday.h"
#include <iostream.h>
#include <string>

void Birthday::bStoneIOfunc()
{
    int iChoice = 0;
    int oChoice = 0;
    ofstream output;
    cout << "How Would You Like To Collect Input?\n";
    cout << "1. Input From File.\n";
    cout << "2. Input to Screen.\n";
    cout << "3. Exit.\n";
    cin >> iChoice;

    switch(iChoice)
    {
        case 1:
            fileInput();
            break;
        case 2:
            cout << "Please Enter the Day You Were Born\n";
            cin >> d;
            cout << "Please Enter Your Birth Month\n";
            cin >> m;
            setDay(d);
            setMonth(m);
            break;
        case 3:
            exit(0);
            break;
    }
            
    cout << "What Would You Like to do With Your Output?\n";
    cout << "1. Output to File.\n";
    cout << "2. Ouput to Screen.\n";
    cout << "3. Exit.\n";
    cin >> oChoice;
    
    string bStone = birthStone();        
    switch(oChoice)
    {    
        case 1:
            cout << "Opening the output File.\n The Output File Will be Called facts.txt";
            output.open("facts.txt");
            output << "Your Birthstone is: " << bStone << "\n";
            output.close();
            cout << "File Saved!\n";
            break;
        case 2:
            cout << "Your Birthstone is: " << bStone << "\n";
            break;
        case 3:
            exit(0);
            break;
    }
}


The errors are at lines:
output << "Your Birthstone is: " << bStone << "\n"; AND
cout << "Your Birthstone is: " << bStone << "\n";

I have no clue why it's not letting me output my string. Fast Reply Is greatly Appreciated as due date is rapidly approaching!

This post has been edited by jayman9: 19 Nov, 2007 - 11:45 PM
User is offlineProfile CardPM
+Quote Post

NickDMax
RE: C++ String Output Error Please Help Asap
20 Nov, 2007 - 06:10 AM
Post #2

2B||!2B
Group Icon

Joined: 18 Feb, 2007
Posts: 2,869



Thanked: 53 times
Dream Kudos: 550
My Contributions
My guess is that the problem was the lack of:

using namespace std; or not using
std::cout << ...

Without this the compiler does not have the declarations for the overloading of the "<<" operator.
User is offlineProfile CardPM
+Quote Post

xxblackrain
RE: C++ String Output Error Please Help Asap
20 Nov, 2007 - 12:05 PM
Post #3

New D.I.C Head
*

Joined: 19 Nov, 2007
Posts: 2


My Contributions
QUOTE(NickDMax @ 20 Nov, 2007 - 07:10 AM) *

My guess is that the problem was the lack of:

using namespace std; or not using
std::cout << ...

Without this the compiler does not have the declarations for the overloading of the "<<" operator.

You dont have to do that in 6.0 ... x.x
User is offlineProfile CardPM
+Quote Post

NickDMax
RE: C++ String Output Error Please Help Asap
20 Nov, 2007 - 08:14 PM
Post #4

2B||!2B
Group Icon

Joined: 18 Feb, 2007
Posts: 2,869



Thanked: 53 times
Dream Kudos: 550
My Contributions
...um... yes you do.



I mean, there might be some magic compiler switch I don't know about, but I don't think so.
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 1/9/09 05:33AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month