【笔记】c++文件
1、文件。
#include <iostream> #include <cstdio> #include <string> #include <cstring> #include <ctime> #include <cstdlib> using namespace std; char *ch = "qwertyuiopasdfghjklzxcvbnm"; void setOut(string dataType) { string out = dataType + ".data"; freopen(out.c_str(), "w", stdout); } char *Random(char* word) { int len = rand() % 99; for (int i = 0; i != len; ++i) word[i] = ch[rand()%26 + 1]; word[len] = '\0'; return word; } void make() { srand(unsigned(time(0))); char word[100]; for (int i = 0; i != 10000; ++i) { cout << Random(word) << endl; } } int main() { setOut("Random"); make(); return 0; }
从文件读,写入文件:
void setIO(string in, string out) { freopen(in.c_str(), "r", stdin); freopen(out.c_str(), "w", stdout); }
浙公网安备 33010602011771号