相关疑难解决方法(0)

int argc,char*argv []是什么意思?

在许多C++ IDE和编译器中,当它为您生成主函数时,它看起来像这样:

int main(int argc, char *argv[])
Run Code Online (Sandbox Code Playgroud)

当我在没有IDE的情况下编写C++代码时,只需使用命令行编译器,我输入:

int main()
Run Code Online (Sandbox Code Playgroud)

没有任何参数.这意味着什么,对我的计划至关重要?

c++ parameters argv command-line-arguments argc

476
推荐指数
8
解决办法
81万
查看次数

What is the proper declaration of main?

What is the proper signature of the main function in C++? What is the correct return type, and what does it mean to return a value from main? What are the allowed parameter types, and what are their meanings?

这是系统特定的吗?这些规则会随着时间而改变吗?如果我违反它们会发生什么?

c++ program-entry-point c++-faq

144
推荐指数
2
解决办法
9万
查看次数

auto是一个基于范围的可选关键字for循环吗?

我记得曾经有人告诉我,

"不需要基于auto内部范围的for循环.如果我们要删除它,那么语言就 不会含糊不清."

这是真实的陈述吗?
以下代码是否有效的C++语法?

for (elem : range){...}  
Run Code Online (Sandbox Code Playgroud)

我原以为这已经是有效的语法,但是当我去编译时
clang++ --std=c++1z,我出现了以下错误:

range-based for loop requires type for loop variable
 for (elem: range){
Run Code Online (Sandbox Code Playgroud)

编译器仍然将其识别为基于范围的for循环,那么为什么它也不能导出类​​型呢?

c++ for-loop auto c++17

9
推荐指数
2
解决办法
780
查看次数

帮助比较argv字符串

我有:

int main(int argc, char **argv) {
   if (argc != 2) {
      printf("Mode of Use: ./copy ex1\n");
      return -1;
   }

   formatDisk(argv);
}

void formatDisk(char **argv) {
   if (argv[1].equals("ex1")) {
       printf("I will format now \n");
   }
}
Run Code Online (Sandbox Code Playgroud)

如何检查C中argv是否等于"ex1"?是否已有功能?谢谢

c argv

2
推荐指数
1
解决办法
1万
查看次数