读写文件--c
来源:互联网 发布:炸鸡叔 绝命毒师 知乎 编辑:程序博客网 时间:2024/06/05 15:38
读文件
一,
string line;
ifstream in;
in.open(filepath);
if(! in){
return;
}
CString str;
CString strtemp;
while (getline(in,line)){
str = line.c_str();
strtemp = str;
}
in.close();
二,
#include <stdio.h>
void main( void )
{
FILE *stream;
char list[30];
int i, numread, numwritten;
if( (stream = fopen( "fread.txt", "r+t" )) != NULL )
{
/* Attempt to read in 25 characters */
numread = fread( list, sizeof( char ), 25, stream );
printf( "Number of items read = %d\n", numread );
printf( "Contents of buffer = %.25s\n", list );
fclose( stream );
}
else
printf( "File could not be opened\n" );
}
写文件
一,
ofstream m_modelout;
m_modelout.open(originmodelfile,ios::out);
if(! m_modelout)
{
cout<< "could not Open File :"<<originmodelfile<<endl;
return ;
}
//m_modelout.seekp(0,ios::beg);
m_modelout.seekp(0,ios::end);
m_modelout.write(str,str.GetLength());
m_modelout.write("\n",1);
二,
#include <stdio.h>
void main( void )
{
FILE *stream;
char list[30];
int i, numread, numwritten;
/* Open file in text mode: */
if( (stream = fopen( "fread.txt", "w+t" )) != NULL )
{
for ( i = 0; i < 25; i++ )
list[i] = (char)('z' - i);
/* Write 25 characters to stream */
numwritten = fwrite( list, sizeof( char ), 25, stream );
printf( "Wrote %d items\n", numwritten );
fclose( stream );
}
else
printf( "Problem opening the file\n" );
}
三,
FILE *out;
if ((out = fopen(ofname, "w")) == NULL) {
fprintf(stderr, "The file %s can't be opened for writing.\n", ofname);
exit(1);
}
fprintf(out, "%s", "dfs");
- 【C/C++】文件读写
- c语言读写文件
- 文件读写(c)
- C#-读写INI文件
- [C++]文件读写操作
- C#读写INI文件
- C 读写文件
- C读写ini文件
- c#FileStream文件读写
- 读写文件 c
- WinAPI C读写文件?
- C语言读写文件
- 文件读写(C++)
- c中的文件读写
- C文件读写
- c读写文件
- c读写Exc文件
- C/C++ 读写文件
- IT农民工如何来美国工作之FAQ
- centos 更新后黑屏
- Linux 识别新加载的disk
- linux安装sourceInsight
- Device eth0 does not seem to be present, delaying initialization
- 读写文件--c
- 《linux设备驱动程序III》学习---第五章
- C#基本语法知识
- 杂记
- python 应用
- ios的一些知识点
- 幸福心理学1幸福的科学
- HTTP详解(2)-请求、响应、缓存
- PHP环境搭建:Windows 7下安装配置PHP+Apache+Mysql环境教程