// writen.cc // write N bytes of 'x' to file "tmp" #include // cerr #include // ofstream #include // atoi #include // assert #include // memset int main(int argc, char *argv[]) { if (argc != 2) { cerr << "usage: " << argv[0] << " \n" << " where is the # of 'x' bytes to write to file \"tmp\"\n"; return 2; } int n = atoi(argv[1]); assert(n >= 0); // make string of length 'n' char *p = new char[n+1]; memset(p, 'x', n); p[n] = 0; // write it to a file { ofstream out("tmp"); out << p; } delete[] p; return 0; }