in the program i am creating a file with specific path.. file name is to be entered by user and then we have to create a file but the code is giving the error written after the code.

void f_Createfile()
    string dirpath;  // stores final name for file with path to stored 
    string file_name; // to enter the name of file enter by user

    cout<<"please enter the file name\n";

    dirpath.append("d:\\");      // appending the string by necessary terms

    ifstream infile;,ios::in); // opening the file with dirpath string.. this line is showing error

        cout<<"\nfile already exist\n";
        cout<<" creating file...\n";
        ofstream onfile;,ios::app);
        cout<<"\nfile is created:\n";

Error   3   error C2664: 'void std::basic_ifstream<_Elem,_Traits>::open(const wchar_t *,std::ios_base::openmode,int)' : cannot convert parameter 1 from 'std::string' to 'const wchar_t *'   c:\Documents and Settings\malaya\My Documents\Visual Studio 2008\Projects\assignment2\assignment2\assignment2.cpp   290

Edited 3 Years Ago by mike_2000_17: Fixed formatting

Please use code tags: [code] //code goes here [/code]

Change dirpath to a std::wstring and in the open operations use dirpath.c_str() instead of dirpath, since you need a C style string (null terminated) in that particular function. Using the c_str() method on the wstring gives you the const wchar_t* I've never used wstring, but give that a shot. I'm not certain if you need an additional header, but since you are using these wide character methods in your code, hopefully you have some idea of that. You definitely need the c_str() one way or the other.

Edited 6 Years Ago by jonsca: n/a

This article has been dead for over six months. Start a new discussion instead.