Thread: Need help.

  1. #1
    Registered User
    Join Date
    Apr 2006
    Posts
    11

    Need help.

    Hello, this is my source code so far:

    Code:
    #include <fstream>
    #include <iostream>
    #include <string>
    
    using namespace std;
    
    string fileName;
    string fileCont;
    
    using namespace std;
    
    int main()
    {
    
    cout<<"What filename should we use? ";
    cin>>fileName;
    cin.ignore();
    cin.get();
    cout<<"What content should we statch into the file? ";
    cin>>fileCont;
    cin.ignore();
    ofstream file ("." << fileName);
    file<<"." << fileCont;
    cin.get();
    return 0;
    }
    and it gives me this error when I compile:

    22 C:\Documents and Settings\user\Desktop\lolcoolnohax.cpp no match for 'operator<<' in '"." << fileName'

    What the hell is happening? I don't have a clue what the error is.

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    >> ofstream file ("." << fileName);

    what are you trying to do there?
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  3. #3
    Registered User
    Join Date
    Apr 2006
    Posts
    11
    Quote Originally Posted by Sebastiani
    >> ofstream file ("." << fileName);

    what are you trying to do there?
    I am, trying to make the user type in a filename and the content for the file, then use ofstream to make the file. Fairly simple but the errors keep coming.


    Kind of let the user make his own custom file.

  4. #4
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    Code:
    ofstream file (fileName.c_str());

  5. #5
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    what exactly do you think this expression evaluates to:

    "." << fileName

    the ofstream object is expecting a const char * as it's first parameter, but that expression does not yield an object of that type (unless of course you have somewhere overloaded operator << (const char *, const string &) to do so).
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  6. #6
    Registered User
    Join Date
    Apr 2006
    Posts
    11
    Thank you.

Popular pages Recent additions subscribe to a feed