Пожалуйста, прочтите новое правило об ограничении использования AI-инструментов. ×

Блог пользователя giang.best.1

Автор giang.best.1, история, 3 года назад, По-английски

Hello, I just switched to macOS M1. Now I'm using VSC to code c++ on codeforces. But I just realized cin.tie(0) doesn't work like in windows. In windows, after entering all input, the output will be written later. But now, the output comes before I finish the input (I'm talking about the problem with multiple test cases). Does anyone have the same problem, can help me to fix it? Thank you guys so much!

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

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

I think the best option would be to create "input.txt" or smth similar and read input from here. You can use ifdefs or for example in CLion 2021, you can edit your configuration and read from file, without changing your code.

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

Use unix pipes, like ./a < a.txt.

»
3 года назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

I'm using Windows and stdout isn't always flushed only when the program exits. Sometimes if the output is a quite long, stdout might get flushed before the program exits (and I don't usually use std::endl).

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

Try this: setvbuf(stdout, nullptr, _IOFBF, BUFSIZ);

»
3 года назад, # |
  Проголосовать: нравится -6 Проголосовать: не нравится

VS code is not fully optimized for M1, it is designed for processors from Intel. Due to the new structure of the processor, VS code may be wrong. I advise you to use Xcode, it fully works for M1

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

It works fine in m1 with g++-11 compiler but doesn't work with clang++. I think you need to change your default compiler in VSC. One more thing How you precompiling bits/stdc++.h in m1 its not working for me.

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

Based on the ideas our friends have commented on before. I found out how the following works. Although it doesn't seem to be very efficient. I created a sh file, which is named "run" like this:

a=$1;
a+=".cpp";
g++ $a -o $1;
./$1 < input.txt;

I put all input to file input.txt Now when I need to run the code, I will write to the terminal:

sh run <name_of_code_without_cpp>
// For ex:
sh run 767A

I did it because it looks like we are running python file xD Anyone has a better idea to share?