How to get rid of this ERROR
-
This is what I am doin... string filename; //filename contains "c:\\new folder\\file1.txt" .... .... ofstream myfile; myfile.open (filename, ios::app); When I compile or built this I get error C2664: 'void __thiscall std::basic_ofstream >::open(const char *,int)' : cannot convert parameter 1 from 'class std::basic_stringaits,class std::allocator >' to 'const char *' No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called Error executing cl.exe. Please help me get rid of this or any suggestion to make changes to this. THANKS
pl_kode wrote:
myfile.open (filename, ios::app);
Change to
myfile.open (filename.c_str(), ios::app);
:)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke -
pl_kode wrote:
myfile.open (filename, ios::app);
Change to
myfile.open (filename.c_str(), ios::app);
:)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke -
This is what I am doin... string filename; //filename contains "c:\\new folder\\file1.txt" .... .... ofstream myfile; myfile.open (filename, ios::app); When I compile or built this I get error C2664: 'void __thiscall std::basic_ofstream >::open(const char *,int)' : cannot convert parameter 1 from 'class std::basic_stringaits,class std::allocator >' to 'const char *' No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called Error executing cl.exe. Please help me get rid of this or any suggestion to make changes to this. THANKS
pl_kode wrote:
myfile.open (filename, ios::app);
does replacing it with something like :
myfile.open (filename.c_str(), ios::app);
works ?Maximilien Lincourt Your Head A Splode - Strong Bad
-
pl_kode wrote:
myfile.open (filename, ios::app);
does replacing it with something like :
myfile.open (filename.c_str(), ios::app);
works ?Maximilien Lincourt Your Head A Splode - Strong Bad
-
It does not show any error like this.. Nor does its creating any file in the specified path. Wt shud I do.
pl_kode wrote:
filename contains "c:\\new folder\\file1.txt"
did you created the "new folder" directory in "C:\" drive, you should not expect open API will do that.
-
It does not show any error like this.. Nor does its creating any file in the specified path. Wt shud I do.
for istance, you may call
myfile.rdstate()
.If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke -
for istance, you may call
myfile.rdstate()
.If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke -
Yes if i give .. ofstream myfile; myfile.open ("c:\\New folder\\file1.txt", ios::app); It works. Even a file is created. But I want it the other way.
can you post how you initialise filename variable. or check the value of filename before open(),
cout << filename.c_str();
-
pl_kode wrote:
I tried it by using rdstate()
What is the return value? Have you read the Rajkumar reply? :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke