Code: Show/Hide #include <iostream> #include <fstream> #include <stdlib.h> #include <windows.h> #include <cstdlib> #include <time.h> #include <sstream> // needed to convert int to string using namespace std; const int LOW = 1; const int HIGH = 1000; void randomfilename(string a, string b, string c, string d, string e) { time_t seconds; time(&seconds); srand((unsigned int) seconds); int random = rand() % (HIGH - LOW + 1) + LOW; string s; std::stringstream out; out << random; s = out.str(); ofstream goods; goods.open(a+s+".txt"); goods<<random; goods.close(); } int main() { randomfilename("hi","hi","hi","hi","hi"); return 0; } |
Code: Show/Hide Compiler: Default compiler
Building Makefile: "C:\Documents and Settings\Owner\Desktop\Programing\c++\VIRUSES\360 mod\Makefile.win" Executing make... make.exe -f "C:\Documents and Settings\Owner\Desktop\Programing\c++\VIRUSES\360 mod\Makefile.win" all g++.exe -c main.cpp -o main.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include" main.cpp: In function `void randomfilename(std::string, std::string, std::string, std::string, std::string)': main.cpp:36: error: no matching function for call to `std::basic_ofstream<char, std::char_traits<char> >::open(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)' C:/Dev-Cpp/include/c++/3.4.2/fstream:695: note: candidates are: void std::basic_ofstream<_CharT, _Traits>::open(const char*, std::_Ios_Openmode) [with _CharT = char, _Traits = std::char_traits<char>] make.exe: *** [main.o] Error 1 Execution terminated |
Code: Show/Hide #include <fstream> #include <time.h> #include <stdlib.h> #include <string> using namespace std; int main() { int namelength = 10; char buf[2] = {0, 0}; string name; srand((int)time(0)); for (int x = 0; x < namelength; ++x) { buf[0] = 'a' + rand() % 26; name += buf; } name += ".txt"; ofstream fout(name.c_str()); if (fout.good()) fout.close(); return 0; } |
Bob Dole.. Bob Dole... Bob Dole...... bob dole.... bob... dole.... wrote: |
Characters aren't really stored as characters, but as their equivalent ascii code.
So what it does is, it takes the ascii code of the letter a and adds a number between 0 and 26 to it. This results is a new ascii code, which can be interpreted as a character. |
Code: Show/Hide if ('a' == 97)
cout << "it's true!" << endl; else cout << "lies!" << endl; |