写文件的头文件
来源:互联网 发布:pr视频剪辑软件下载 编辑:程序博客网 时间:2024/04/18 08:26
#include <iostream>
#include <fstream>
ofstream f1("D:\\Projects\\Chris_lu\\Demo\\x64\\Debug\\try.txt",ios::trunc);
if(!f1)
{
cout << "open file error." << endl;
// return 0;
}
f1.write(strFormula.c_str(),strFormula.length());
f1.close();
为了打开一个文件供输入或输出,除了iostream头文件外,还必须包含头文件:
#include <fstream>
2010-09-11 22:39
小学期的计算机实习期间,用老师给的一个输出字符的头文件来做俄罗斯方块。为了调试方便就用上了VS2008,但是悲剧的事情随之而来,一开始的时候编译上海没有什么问题,在加了所给的头文件之后,就一直出现 cannot convert parameter 6 from 'const char [3]' to 'LPTSTR' 的错误。起初以为是我的VS2008的设置问题,一狠心就卸了2008装上了最新的2010.本以为问题就此解决,没想到一个来小时的折腾,换来的是一样的结果,无奈之下,只好用DEV来开发了。(因为2008的缘故,VC6在安装过程中一直会报错)
今天找到原因,造成不能运行的原因主要在于2008和2010中增加了一些参数类型的安全性检查,所以通常在6.0没有问题的LPCTSTR与 const char之间的转换到了2008中就行不通了。
于是微软给出的解决办法有两个:
今天找到原因,造成不能运行的原因主要在于2008和2010中增加了一些参数类型的安全性检查,所以通常在6.0没有问题的LPCTSTR与 const char之间的转换到了2008中就行不通了。
于是微软给出的解决办法有两个:
- Change your project configuration to use multibyte strings. Press ALT+F7 to open the properties, and navigate to Configuration Properties > General. Switch Character Set to "Use Multi-Byte Character Set".
- Indicate that the string literal, in this case "Hello world!" is of a specific encoding. This can be done through either prefixing it with L, such as L"Hello world!", or surrounding it with the generic _T("Hello world!") macro. The latter will expand to the L prefix if you are compiling for unicode (see #1), and nothing (indicating multi-byte) otherwise.
CStdioFile file;
// CFileException mExcept;
file.Open(L"E:\\1.txt",CFile::modeCreate|CFile::modeWrite);
if(!file)
{
cout << "open file error." << endl;
// return 0;
}
// CFileException mExcept;
file.Open(L"E:\\1.txt",CFile::modeCreate|CFile::modeWrite);
if(!file)
{
cout << "open file error." << endl;
// return 0;
}
file.WriteString (strItemName);
file.WriteString(L"\n");
file.WriteString(L"\n");
file.Close();
- 写文件的头文件
- 写头文件注意
- 头文件怎么写
- 如何写头文件
- 写好C语言的头文件
- 写好C语言的头文件
- 写一个.h的头文件
- 给你写的launchpad430--IAR头文件
- Arduino 写头文件的bug
- C++的头文件和实现文件分别写什么
- 写xml文件时头文件的编码
- C++的头文件和实现文件分别写什么
- C++的头文件和实现文件分别写什么
- C++的头文件和实现文件分别写什么
- C++的头文件和实现文件分别写什么
- C++的头文件和实现文件分别写什么
- C++的头文件和实现文件分别写什么
- C++的头文件和实现文件分别写什么
- 贾也:如何读懂移民潮下的经济隐喻
- 分布式系统与集群的区别
- Red Hat Enterprise Linux 5安装后中文乱码解决
- 北理工胡星斗教授:只有废除特权政治 中国才有希望
- SQL server如何定时执行SQl脚本(函数)
- 写文件的头文件
- PDO 的事务处理
- java 命令行引用jar包的方法 的整理
- 等价,偏序和全序
- 温故而知新——关系型数据库
- 创业 和 移动互联网
- IPv6学习笔记(3)----IPv6地址表示方式
- 编码转换
- 常用的ADB命令