1

I am new in c++. I tried to create the binary file in c++. But not able to create it.Below is my source code.

void main()
{
 ofstream myfile;
 myfile.open("D:\get\data.bin",ios::binary);
 if (myfile.is_open()) 
 cout<<"hi"<<endl;
 else
     cout<<"bye"<<endl;
}

I always get bye output only. My required target is to create a binary file in D directory with the data as a file name.I am using VS2010 and os is win 7. for providing the help

4

1 回答 1

8

您必须将反斜杠加倍:

"D:\\get\\data.bin"

看看转义字符

于 2013-09-04T18:01:12.887 回答