小编Bra*_*art的帖子

C语言中的Char数组和scanf函数

我期望在以下代码中得到错误,但我没有。我没有使用&标志。我也在编辑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)

c arrays scanf

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

C++泛型函数的灵活性

我想制作灵活的通用函数,它的返回可以处理多个未知类型.

#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)

c++ templates

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

使用set iterator在`it-1`上出错

在下面的代码我无法识别--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)

c++ iterator set

0
推荐指数
1
解决办法
129
查看次数

C 编程对‘WinMain@16’的未定义引用

我正在尝试使用带有记事本的 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)

c windows

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

标签 统计

c ×2

c++ ×2

arrays ×1

iterator ×1

scanf ×1

set ×1

templates ×1

windows ×1