ios problem!

closed account (9wX36Up4)
#include<iostream>
#include<fstream>

using namespace std;

main(){
       short a;
      
      fstream Kaynak;
      Kaynak.open("Kaynak.txt",ios::in|ios::trunc|ios::out);
      if(Kaynak.is_open()){
          cout<<"Success!";
          for(a=1;a<=36;a++){
              Kaynak<<a;
              if(a==36){a=1;}
              }
          }
      else
          cout<<"Fail!";
      Kaynak.close();
      return 0;
}

I have a problem with this. It is writing a's value to Source.txt then i want it to overwrite the next value of a.
I don't know what to do.
You want to make an infinite loop which sets the contents of a file to a number from 1 to 36 ?
open and close the file inside the loop, or use seekp (though I have a feeling that if the file contained 36 and you wanted to write 1 in it, the result would be 16. If that happens, write a ' ' to clear that second number. I honestly don't know how to erase things from a file..).

By the way,
I'd ask why would you want to do that, but for some reason I'm afraid of the answer. Is this really what you need?
closed account (9wX36Up4)
yes this is what i need i want to make a good dice program(u already know rand() is not good )
is there something u afraid and i dont know how to clear
Last edited on
closed account (9wX36Up4)
So anybody answer me?
rand is as good as you could possibly need.
Is your idea that you'll open the file and you'll find a random number in it?
You don't need a file.. Try
1
2
3
cout << "press enter when you feel like it";
cin.get();
cout << "a random number is " << clock()%36+1;
Of course, put it in main and #include <ctime>.
closed account (9wX36Up4)
thanks it solved all my problems
Topic archived. No new replies allowed.