Блог пользователя helpme

Автор helpme, история, 9 лет назад, По-английски

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!

  • Проголосовать: нравится
  • +13
  • Проголосовать: не нравится

»
9 лет назад, # |
  Проголосовать: нравится +13 Проголосовать: не нравится

The file itself is alright in both cases.
I am able to reproduce the problem only when I open the first file in Notepad.
Perhaps it (wrongly) decides the file is in UTF-16 instead of ASCII.