fstream调用文件,包含类fstream定义的头文件是

1 , 包含类fstream定义的头文件是fstream、ifstream、ofstream都是包含在头文件fstream中,所以需要#include <fstream>不仅仅是iostream类对象,不同的输入流对象都有一个getline函数 , 如fstream类对象等都有的 。你说的单纯的getline函数应该是在stdio.h中定义,c++中对应的是cstdio头文件中 。
2,怎么用c写一个程序stdcin用户输入一个txt文件名程序用ifstream参考程序【编译环境 Dev C++】#include <iostream>#include <fstream>#include <string>using namespace std;int main() string fileName = ""; cin >> fileName; //获取文件名 ifstream file(fileName.c_str()); //打开文件 char buffer[16384]; while(!file.eof()) file.getline(buffer, 16383); //一行中只会读取16383个字符 , 过多会忽略掉 cout << buffer << endl; //输出 } cin.get();cin.get(); //只是为了在屏幕上保留输出结果,可以注释掉 return 0;}
3 , fstream头文件文件问题应当都可以 。ofstream -- 输出文件流 classfstream -- 输入/输出文件流 class fstream filestr;filestr.open ("test.txt", fstream::app);第2个参数:fstream::app 尾加文件fstream::in 输入文件fstream::out 输出文件ofstream outfile;outfile.open ("test.txt",ios_base::app);app -- 输出文件,尾加ate -- 打开时,文件位置定在文件尾注意定义文件流对象的参数ofstream out("file.txt", ios::app) //app参数即尾接, 打开文件后再EOF前开始写入fstream是一个头文件的名字,属于c++的,主要包含文件操作的类和方法linux 中该头文件路径/usr/include/c++/4.1.1/fstream【fstream调用文件,包含类fstream定义的头文件是】
4,fstream 读文件总是失败ifstream infile(filename.c_str(),ios::in)应该是这句有问题,楼主可以参看资料:http://blog.csdn.net/jing0611/article/details/4387690ifstream infile(filename.c_str(),ios::in)这句有问题文件名是不是连文件后缀一起加上了还有文件路径等 。建议你打断点调试一下iostream>.txt";endl; return 0;\documents and settings\.close();<,ios;桌面\\< #include ch<.open("c:\ #include using namespace std; int main() { fstream file; file; cout<::in); string ch; getline(cin,ch); file;\administrator\\1#include <

    推荐阅读