![](https://img-blog.csdnimg.cn/20201014180756916.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
C++文件操作
nuoshueihe
这个作者很懒,什么都没留下…
展开
-
append
#include #include using namespace std;int main(){ char fileName[80]; char buffer[255]; cout << "Please re-enter the file name: "; cin >> fileName; ifstream fin(fileName); if (fi原创 2012-11-28 13:32:53 · 435 阅读 · 0 评论 -
File Size
#include #include using namespace std;int main () { long begin,end; ifstream myfile ("example.txt"); begin = myfile.tellg(); myfile.seekg (0, ios::end); end = myfile.tellg(); myfile.cl原创 2012-11-28 15:07:08 · 405 阅读 · 0 评论 -
File Read Write
Reads information from the file and outputs it onto the screen#include #include using namespace std;int main (){ char data[80]; ofstream outfile; outfile.open("file.dat"); cout << "原创 2012-11-28 15:00:34 · 716 阅读 · 0 评论 -
Abstract Class
Create an abstract class.#include using namespace std;class area { double dim1, dim2; public: void setarea(double d1, double d2) { dim1 = d1; dim2 = d2; } void getdim(double &d原创 2012-11-28 16:12:01 · 400 阅读 · 0 评论 -
Stream iterator
#include #include using namespace std;int main(){ istream_iterator in_it(cin); do { cout << *in_it++; } while (*in_it != '.'); return 0;}Use istream_iterator#include #inclu原创 2012-11-28 15:53:46 · 596 阅读 · 0 评论 -
Object Serialization
Save object to file with customized operator#include #include #include using namespace std; class phonebook { char name[80]; char areacode[4]; char prefix[4]; char num[5];public:原创 2012-11-28 15:38:46 · 336 阅读 · 0 评论 -
istrstream
#include #include using namespace std;main() { char s[] = "text and binary mixed\23\22\21\a\t\n"; istrstream ins(s); char ch; while (!ins.eof()) {原创 2012-11-28 15:11:41 · 676 阅读 · 0 评论 -
File Status
#include #include using namespace std;int main(int argc, char *argv[]){ char ch; if(argc!=2) { cout \n"; return 1; } ifstream in(argv[1]); if(!in) { cout << "Cannot open原创 2012-11-28 15:10:06 · 494 阅读 · 0 评论 -
File Read
Write char to a file#include #include using namespace std;int main(int argc, char *argv[]){ char ch; if(argc!=2) { cout \n"; return 1; } ofstream out(argv[1], ios::out | ios原创 2012-11-28 15:05:04 · 2839 阅读 · 0 评论 -
Use eof() to read and display a text file.
#include #include using namespace std;int main(int argc, char *argv[]){ char ch; ifstream fin("text.txt"); if(!fin) { cout << "Cannot open file.\n"; return 1; }/**while(!fin.e转载 2012-11-28 14:45:12 · 376 阅读 · 0 评论 -
Convert spaces to |s.
#include #include using namespace std;int main(int argc, char *argv[]){ if(argc!=3) { cout \n"; return 1; } ifstream fin(argv[1]); // open input file ofstream fout(argv[2]); //原创 2012-11-28 14:42:43 · 437 阅读 · 0 评论 -
Use exceptions to watch for and handle I/O errors.
#include #include #include using namespace std;struct inventory { char item[20]; int quantity; double cost;};int main(){ int completion_status = 0; ofstream fout; fout.exceptio原创 2012-11-28 14:41:11 · 491 阅读 · 0 评论 -
Binary File
Write numbers to a binary file and read them back#include #include using namespace std;int main(void){ float fnum[4] = {11.22, -33.44, 55.66, 77.88}; int i; ofstream out("numbers.asc",原创 2012-11-28 14:00:52 · 919 阅读 · 0 评论 -
由C++的fstream来说明I/0流文件
在C++中,有一个stream这个类,所有的I/O都以这个“流”类为基础的,包括我们要认识的文件I/O,stream这个类有两个重要的运算符: 1、插入器(<<) 向流输出数据。比如说系统有一个默认的标准输出流(cout),一般情况下就是指的显示器,所以,cout<<"Write Stdout"<<'/n';就表示把字符串"Write Stdout"和换行字符('/n')输出到标准输转载 2012-11-28 13:56:17 · 462 阅读 · 0 评论 -
Array Based IO
#include #include using namespace std;int main(){ char *p; ostrstream outs; // dynamically allocate array outs << "C++ array-based I/O "; outs << -10 << hex << " ";原创 2012-11-28 13:42:53 · 405 阅读 · 0 评论 -
rename
Demonstrate rename() and remove()#include #include #include #include using namespace std;int main(int argc, char *argv[]){ int result; if(argc != 2) { printf("usage: EraseRenname \n"原创 2012-11-28 15:50:54 · 409 阅读 · 0 评论