Please read the new rule regarding the restriction on the use of AI tools. ×

giang.best.1's blog

By giang.best.1, history, 3 years ago, In English

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!

  • Vote: I like it
  • -4
  • Vote: I do not like it

| Write comment?
»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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

  • »
    »
    3 years ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

    Thank you. But in a contest, it's not effective because it takes a bit more time to run the code. Maybe I'll try to use another code editor.

»
3 years ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

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 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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

»
3 years ago, # |
  Vote: I like it -6 Vote: I do not like it

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 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Me too, bits/stdc++.h doesn't work. I wrote include for all the libraries :(

»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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?