I have encountered an error, saying that std::size() is not a member of std. Then I found this link: Why std::size() is not a member of std in gcc 8.2.0 Eventually, my code works well after I compile the file with g++ -std=c++17 myFile.cpp
. Now, I tried g++ -std=c++17 6.cpp -o - 6.out
as the previous link suggested, and it did not work. Any comments?

- 571
- 1
- 5
- 16
-
4I'm quite confused by your question. It seems you have already learned that `std::size` is a C++17 feature, and this is not enabled by default in `g++`, right? Then your title seems to suggest you don't want to have to explicitly enable this every time, but your question seems to be about a misunderstanding on how to specify the output file name? Please try to clarify what you are asking. It will help to explain exactly what you are hoping for, and what happens instead, including any error messages. – BoBTFish Nov 20 '19 at 09:46
-
3`g++ -std=c++17 6.cpp -o - 6.out` looks like it has an extra `-` (dash) between `-o` and filename. – Yksisarvinen Nov 20 '19 at 09:47
-
I edited that answer, should be working now. – Yksisarvinen Nov 20 '19 at 09:49
-
g++ -std=c++17 6.cpp -o 6.out g++: error: 6.cpp: No such file or directory g++: fatal error: no input files compilation terminated. – kkxx Nov 20 '19 at 09:54
-
@BoBTFish, I thought using g++ -std=c++17 6.cpp -o - 6.out could get rid of the -std=c++17 in g++ command line. – kkxx Nov 20 '19 at 09:55
-
@kkxx Maybe your "6.cpp" does not exist at the location where you call `g++` – Petok Lorand Nov 20 '19 at 09:55
-
7You shouldn't just copy and paste commands from the Internet (even from Stack Overflow) to your computer *without any understanding what they are doing*. You have a working command `g++ -std=c++17 myFile.cpp`. Now read up on what `-o` is doing and what should follow it and only then add it to your build command. – Yksisarvinen Nov 20 '19 at 09:59
-
1And no, nothing can get rid of `-std=c++17` in your build command. The only possibility would be to upgrade the compiler version, but such version *doesn't exist yet*. Newest `gcc` version uses C++14 by default. If you want to use C++17 features, you have to tell that to your compiler. – Yksisarvinen Nov 20 '19 at 10:03
-
@kkxx The command works but you made a typo. As @Yksisarvinen told you, you have an extra `-` character between `-o` and `6.out`. Just remove this extra dash and it will work as expected. – Fareanor Nov 20 '19 at 10:28
-
1The amount of flags your compiler needs to function properly shouldn't concern you, since you shouldn't invoke it manually most of the time. Consider using a makefile (or some other build system). – HolyBlackCat Nov 20 '19 at 10:29
-
If you are using the bash shell, `alias g++17='g++ -std=c++17'` might be useful for your situation. – Eljay Nov 20 '19 at 12:57
2 Answers
This can be done with a shell alias.
If you really want to get rid of having to type -std=c++17
you can set an alias in your .bashrc
or .zshrc
file (or whatever rc file corresponding to the shell you use).
I mainly use zsh but it's the same process for almost all shells...
Find out which shell your using with echo $SHELL
this will likely either be /bin/zsh
or /bin/bash
. then proceed with the following depending on your shell
vim ~/.zshrc
or vim ~/.bashrc
(depending on your shell)
add alias g++="g++ -std=c++17"
then save the file
restart your current shell/terminal window (close and reopen)
next time you go to compile with:
g++ ...
the shell will replace it with g++ -std=c++17
and saved yourself 10 keystrokes.
Note: This isn't advised if you're going to be working with various compliler versions for different projects down the road but if you're asking this question it likely will never matter. glhf!

- 167
- 3
- 11