文件读写,没认真看,和java差不多,看了一下基础的:
#include<iostream.h> #include<fstream.h> class sample7 { }; int main() { ofstream file;//文件输出 file.open("test.txt");//打开文件 file<<"Helloworld \n"<<75;//玩文件里写Hello world 回车换行 75 file.close();//关闭 ifstream file2;//文件读取 char str[20]; int a; //char *str; //这样定义的字符串不行!编译警告没分配空间,运行报内存不能写的错误。 file2.open("test.txt"); file2>>str;//读取的写到字符数组中。 file2>>a;//将75写到a;每次读取一个单词,以空格区分!? cout<<str<<endl; cout<<a<<endl; file2.close(); return 0; }
集合类教程没看,除了语法些许差别,基本和java一致。