请各位高手,帮忙解答vc编程问题。。谢谢!!
程式功能为:把从键盘输入的字符串,读入指定(log,txt)文件程式可以运行!!可是运行结果为乱码! 请求各位大虾帮助!
#include "string"
#include<iostream>
using namespace std;
void file (string y)
{
FILE *fp;
fp=fopen("c:\log.txt","w+");
if (fp)
{
fwrite (&y,sizeof(y),100,fp);
}
fclose(fp);
}
void main()
{
string x;
while (1)
{
cout <<"input a string:"<< "\n";
cin >> x;
file (x);
// cout<<x << "\n";
}
}