[英]how to get rid of -std=c++17 in g++ command line?
I have encountered an error, saying that std::size() is not a member of std.我遇到了一个错误,说 std::size() 不是 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
.然后我找到了这个链接: Why std::size() is not a member of std in gcc 8.2.0最终,在我使用
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.现在,我按照上一个链接的建议尝试
g++ -std=c++17 6.cpp -o - 6.out
,但没有成功。 Any comments?任何意见?
Compile with the following command:使用以下命令编译:
g++ -std=c++17 yourFile.cpp -o output_executable_name
Replace yourFile.cpp
by the name of your .cpp
file, and output_executable_name
by the name you want, it will generate an executable with this name.将
yourFile.cpp
替换为.cpp
文件的名称,并将output_executable_name
替换为您想要的名称,它将生成具有此名称的可执行文件。
Find here more information on g++ compiler.在此处查找有关 g++ 编译器的更多信息。
This can be done with a shell alias.这可以通过 shell 别名来完成。
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).如果您真的想摆脱键入
-std=c++17
的麻烦,您可以在.bashrc
或.zshrc
文件(或与您使用的 shell 对应的任何 rc 文件)中设置别名。
I mainly use zsh but it's the same process for almost all shells...我主要使用zsh,但几乎所有shell都使用相同的过程......
Find out which shell your using with echo $SHELL
this will likely either be /bin/zsh
or /bin/bash
.找出您与
echo $SHELL
一起使用的 shell 这可能是/bin/zsh
或/bin/bash
。 then proceed with the following depending on your shell然后根据您的 shell 进行以下操作
vim ~/.zshrc
or vim ~/.bashrc
(depending on your shell) vim ~/.zshrc
或vim ~/.bashrc
(取决于你的外壳)
add alias g++="g++ -std=c++17"
then save the file添加
alias g++="g++ -std=c++17"
然后保存文件
restart your current shell/terminal window (close and reopen)重新启动您当前的外壳/终端 window (关闭并重新打开)
next time you go to compile with:下次你用 go 编译时:
g++...
the shell will replace it with g++ -std=c++17
and saved yourself 10 keystrokes. g++...
shell 将用g++ -std=c++17
替换它,并为自己节省了 10 次击键。
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!
哈哈!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.