Weird problem with writing txt.file

Revision en1, by helpme, 2015-07-24 00:59:17

Hello everyone,

Today I had to make a test case with 1000 characters, so I had to write a txt file. I wrote this program:

#include<bits/stdc++.h>
using namespace std;
int main ()
{
    freopen("zxq.txt" , "w" , stdout) ;
    for(int i = 0 ; i < 1000; i++)
        cout << rand() % 2 << ' ' ;
}

but, when I opened the zxq.txt file there were some other charaters like '‱' and '‰' not '0' or '1' ! But, when I changed the code as following it worked correctly:

#include<bits/stdc++.h>
using namespace std;
int main ()
{
    freopen("zxq.txt" , "w" , stdout) ;
    for(int i = 0 ; i < 1000; i++)
        cout << rand() % 2 ;
}

Can anyone please explain why it is working like this or how to resolve this problem?
Thanks in advance!

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English helpme 2015-07-24 00:59:17 829 Initial revision (published)