Mar 5, 2013 at 8:39am
If I were to run this code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
#include <iostream>
#include <fstream>
int main() {
std::fstream file;
file.open("Note.txt", std::ios::out);
if(file.is_open() == true) {
for(;;)
file<<"0123456789"<<std::endl;
}
file.close();
return 0;
}
|
Would there be a possibility that this will take over my hard drive space since the for loop is endless?
Last edited on Mar 5, 2013 at 8:41am
Mar 5, 2013 at 9:12am
it probably would, but very slowly. You can stop your program way before it becomes an issue.
EDIT: 50 Mb in 8 seconds. Really slow.
Last edited on Mar 5, 2013 at 9:13am
Mar 5, 2013 at 9:57am
remove the for(; ;) statement and it won't run endless.
Mar 5, 2013 at 10:57pm
Oh ok well I understand the code entirely and I also know how controll it. I was just curious of the consequences.
Mar 6, 2013 at 5:20am
Remove std::endl at the file writing routine and it will eat space like 10 times faster (450 MB / 8 sec for me)
Mar 6, 2013 at 7:40am
Lol thanks for the tip. MiiNiPaa
Last edited on Mar 6, 2013 at 7:41am
Mar 6, 2013 at 1:25pm
aha! I remember doing something similar to this at uni, on a friends account!
Created a few thousand folders, then moved all his work in the end folders, so he had to click to the end of each on to see if his work was there!
Mar 6, 2013 at 7:28pm
Some people use it in a virus to make someone's computer slower and to give them less space on their HDD.
You can also use:
1 2 3 4 5 6
|
while(true){
// code here
}
|
might be a little faster??
Last edited on Mar 6, 2013 at 7:30pm