Weird problem with writing txt.file

Правка en1, от 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!

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en1 Английский helpme 2015-07-24 00:59:17 829 Initial revision (published)