我期望在以下代码中得到错误,但我没有。我没有使用&标志。我也在编辑chars的数组。
#include <stdio.h>
int main()
{
char name[10] ="yasser";
printf("%s\n",name);
// there is no error ,
// trying to edit array of chars,
// also did not use & sign.
scanf("%s",name);
// did not use strcpy function also.
printf("%s\n",name);
return 0;
}
Run Code Online (Sandbox Code Playgroud) 我想制作灵活的通用函数,它的返回可以处理多个未知类型.
#include <iostream>
template<typename U, typename V>
U Max(U arg1, V arg2) {
return arg1 > arg2 ? arg1 : arg2;
}
using namespace std;
int main()
{
double x = 9.88;
int n = 8;
cout << Max(x, n) << endl; // output is 9.88
int z = 4;
double r = 5.88;
// output is 5 not 5.88, I want to code one function deal with all types.
cout << Max(z, r) << endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud) 在下面的代码我无法识别--it和之间的区别it-1.同样是words.end()值超出设定范围?
#include <iostream>
#include<set>
using namespace std;
int main()
{
set<string> words;
words.insert("test");
words.insert("crack");
words.insert("zluffy");
set<string>::iterator it=words.end();
cout<<*(--it)<<endl;//just works fine
cout<<*(it-1)<<endl;//Error
return 0;
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用带有记事本的 gcc (tdm-1) 4.7.1 和 Windows 10 上的命令提示符编译以下代码。以前将 bin 文件夹路径添加到全局变量,但是当我尝试编译时出现以下错误“未定义引用到`WinMain@16'"。但是相同的代码在代码块上也能正常工作!。
PS:我像这样编译它“cd /d path of code then gcc filename.c”
#include<stdio.h>
int main(){
printf("Hello world");
return 0;
}
Run Code Online (Sandbox Code Playgroud)