文件的读写
来源:互联网 发布:php面向对象面向过程 编辑:程序博客网 时间:2024/05/18 19:35
在getline那边挣扎好久,终于算是编译通过,写出来了。这算是我打响学习的第一炮,接下来继续努力。
int main()
{
string buff ;
char filename[30];
ofstream infile;
cout << "please input filename" << endl;
cin >> filename;
cout << endl;
infile.open(filename,ios::out|ios::app) ;
if(!infile)
{
cerr<<"open failed" << filename <<endl;
exit(0);
}
infile << "i" <<" ";
infile << "love" << " " ;
infile << " you " << " ";
cout << "input number:" << endl;
cin >> buff;
infile << buff << endl;
infile.close();
ifstream onfile;
onfile.open(filename);
if(!onfile)
{
cerr<< "open failed" << filename << endl;
exit(0);
}
onfile.seekg(0,ios::end);
double m_nLength = onfile.tellg();
onfile.seekg(0);
cout << "The number is:" << endl;
char *str = (char*)malloc((m_nLength)*sizeof(char));
while(onfile.getline(str,m_nLength,'\n'))
//while(getline (onfile,str))
cout<<str;
onfile.close();
return 0;
}
- 串口的读写,文件读写
- INI文件的读写
- 读写文件的例子
- INI文件的读写
- 关于文件的读写
- 文件的读写操作
- 文件的读写操作
- properties文件的读写
- 读写服务器端的文件
- 位图文件的读写
- C++文件的读写
- ini文件的读写
- 文件的读写
- 自定义文件的读写
- 文件的读写操作
- 文件的读写
- 文件读写的问题
- Python文件的读写
- 多播委托的使用举例、出现异常时多播委托需要用迭代方法列表、匿名方法、lambda表达式
- Android Studio查看和取消所有断点
- poj1061 青蛙的约会(扩展欧几里德算法)
- android之混淆
- 挖坑了挖坑了,走过路过不要错过 。。。
- 文件的读写
- 创建数据库并插入数据 + MySQL常用数据类型
- 理解JS中的call、apply、bind方法
- 笨办法学 Python · 续 第一部分:预备知识
- 练习2
- hdu 6092 递推
- Java里\r和\n的区别
- java并发编程
- Windows下安装Hadoop(免cygwin)