IfStream,Ofstream

Thank you cause u helpd me whit previous problem but im stuck again.

I saw i can retrive number whit ifstream but i dont know how to check if its same like in .txt file.need to retrive

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include "stdafx.h"
#include <cstdlib>
#include <ctime>
#include <iostream> 
#include <fstream>
#include <conio.h>

using namespace std; 
   int main() 
{     
	for(int i=0; i<90; i++)
	   {cout<<" "<<i<<endl;}

	
srand((unsigned)time(NULL));  


int random_integer;     

ofstream myfile;
myfile.open ("nr.txt");
for(int i=0; i<20; i++)
{  
   
	random_integer = (rand()%90)+1; 
	cout <<" "<< random_integer;
	myfile <<" "<< random_integer;
	int t = clock();
    while(clock()-t < 10*500);
} 
myfile.close();

 getch();

}


i think i need a for() and a new int variable. someone can help me to randomize unique numbers?

Thank you cause u help beginers like me...hope in future i will make same. :)
do exactly what you want ?
you write the numbers to the file.after Do you want to read from there?
i want to check in real time nr.txt and if the randomed number its like one of previous numbers to change it(random another instead) but in same session
1
2
3
4
5
6
7
8
ofstream myfile;
	random_integer = (rand()%90)+1;    
	myfile.open ("nr.txt");
	myfile <<" "<< random_integer;
	cout <<" "<< random_integer;
	myfile.close();
	int t = clock();
    while(clock()-t < 10*500);



If i put like that in nr.txt dont write all numbers only one.he delete previous number that was randomed and write the new one...
ok now i change
myfile.open ("nr.txt",ios::app );

but how i can make to delete previous numbers and insert the new one?(20 numbers)
Topic archived. No new replies allowed.