why the production of the useless program I did is weird *_*
it produce 10 ABCDEFG folders in different orders then after it finishes it produced folders with names like:
_concurrence_unlock_error
_globals
M_replace_aux
The string literal will decay to a pointer (const char*) pointing to the first character in the string literal " ABCDEF ". When you add the counter you get a pointer that points that many bytes ahead. So when counter is 1 it will point to the A (and will be treated as the string "ABCDEF "), when counter is 2 it will point to the B (and will be treated as the string "BCDEF "), etc.
When you go beyond the string length (counter > 9) it will point to whatever is stored after the string literal in memory. Most (all?) string literals that are used in the program are probably stored after each other in memory so that is probably why you get all those other weird names.
As Peter87 has alread said, part of the problem is that the string literal (" ABCDEF ") is treated as a pointer and operator+ (with the counter) is performing pointer arithmetic. (And thereby finding all kinds of weird names in memory to use.)
Another part is there is no automatic conversion of integers to string, so this will also fail (to use the same tricks as is used on line 13 of the original post.)
#include <iostream>
#include <sstream>
#include <string>
#include <direct.h> // for _mkdir
usingnamespace std;
int main()
{
int counter = 0;
while(counter < 10)
{
ostringstream oss;
oss << "ABCDEF " << counter;
_mkdir(oss.str().c_str());
counter++;
}
return 0; // main returns 0 even if it's not explicit,
// so you might as well make this clear!
}
Sweet I just created a folder with hundreds of thousands of folders ^_^
and with the <direct.h> header I don't have to use shell to use mkdir function , just using microsoft run time library