c++怎样实现数据存入指定的TXT文档
(2011-05-09 16:52:43)
标签:
存入数据txt文档 |
分类: C |
原文地址:http://blogold.chinaunix.net/u2/82702/showart_2066480.html
作者:叶飘零 #include
#include <iostream>
#include <fstream>//文件流头文件,读写文件时用
using namespace std;
int main()
{
ifstream fin( "D:\data.txt" );
if( !fin )
{
cerr#include <iostream>
#include <fstream>//文件流头文件,读写文件时用
using namespace std;
int main()
{
ifstream fin( "D:\data.txt" );
if( !fin )
{
cerr << "文件打开失败" << endl;
return -1;
}
int a, b;//接受数值
char c;//接受逗号
//按照int类型读入,遇到“,”时停止第一次读取,
//然后将","读入c,然后读取后面的数字作为b
fin >> a >> c >> b;
cout<< "从文件中读入的a的值为:" << a << endl;
cout<< "从文件中读入的b的值为:" << b << endl;
fin.close();
a++;
b++;
cout<<"修改后的a的值为:"<<a<<endl;
cout<<"修改后的b的值为:"<<b<<endl;
ofstream fout( "D:\data.txt" );
fout << a << "," << b << endl;
fout.close();
return 0;
} << "文件打开失败" << endl;
return -1;
}
int a, b;//接受数值
char c;//接受逗号
//按照int类型读入,遇到“,”时停止第一次读取,
//然后将","读入c,然后读取后面的数字作为b
fin >> a >> c >> b;
cout<< "从文件中读入的a的值为:" << a << endl;
cout<< "从文件中读入的b的值为:" << b << endl;
fin.close();
a++;
b++;
cout<<"修改后的a的值为:"<<a<<endl;
cout<<"修改后的b的值为:"<<b<<endl;
ofstream fout( "D:\data.txt" );
fout << a << "," << b << endl;
fout.close();
return 0;
}
#include <fstream>//文件流头文件,读写文件时用
using namespace std;
int main()
{
ifstream fin( "D:\data.txt" );
if( !fin )
{
cerr#include <iostream>
#include <fstream>//文件流头文件,读写文件时用
using namespace std;
int main()
{
ifstream fin( "D:\data.txt" );
if( !fin )
{
cerr << "文件打开失败" << endl;
return -1;
}
int a, b;//接受数值
char c;//接受逗号
//按照int类型读入,遇到“,”时停止第一次读取,
//然后将","读入c,然后读取后面的数字作为b
fin >> a >> c >> b;
cout<< "从文件中读入的a的值为:" << a << endl;
cout<< "从文件中读入的b的值为:" << b << endl;
fin.close();
a++;
b++;
cout<<"修改后的a的值为:"<<a<<endl;
cout<<"修改后的b的值为:"<<b<<endl;
ofstream fout( "D:\data.txt" );
fout << a << "," << b << endl;
fout.close();
return 0;
} << "文件打开失败" << endl;
return -1;
}
int a, b;//接受数值
char c;//接受逗号
//按照int类型读入,遇到“,”时停止第一次读取,
//然后将","读入c,然后读取后面的数字作为b
fin >> a >> c >> b;
cout<< "从文件中读入的a的值为:" << a << endl;
cout<< "从文件中读入的b的值为:" << b << endl;
fin.close();
a++;
b++;
cout<<"修改后的a的值为:"<<a<<endl;
cout<<"修改后的b的值为:"<<b<<endl;
ofstream fout( "D:\data.txt" );
fout << a << "," << b << endl;
fout.close();
return 0;
}
PS:在vc20008中实现
程序:
ofstream Curfile;
Curfile.close();
Curfile.clear();
Curfile.open("F://Flicker
Project//Cur_data.txt",ofstream::out|ofstream::app);
Reffile<<(int)*(pRefData +
increase)<<endl;
Curfile.close();
前一篇:公共营养常识
后一篇:在MATLAB中读入视频