有没有一种方法可以在VS代码中使用get_int函数?

时间:2020-08-07 07:04:10

标签: c visual-studio-code cs50

编辑我的问题已解决非常感谢 问题是我只包含了cs50.h,却没有包含cs50.c,而我所拥有的库是一个仅包含GetInt但不包含get_int的旧库 当我下载新库时,一切正常

我正在修CS50x课程,我想使用public MainWindow() { InitializeComponent(); DataContext = new MainWindowViewModel(); } 函数,该函数包含在VS代码的cs50库中... 我下载了cs50库并将cs50.h和cs50.c复制到d:\ MinGW \ bin

我的代码是

get_int

当我尝试使用它进行编译时

#include <stdio.h>
#include <cs50.h>


int main(void)
{
    int age = get_int("Age?");
    int days=age*365;
    printf("Your age is %i which means that you are %i days old", age, days);
}

它写

gcc 0.c -o 0

vs代码的自动完成功能没有0.c: In function 'main': 0.c:7:15: warning: implicit declaration of function 'get_int' [-Wimplicit-function-declaration] 7 | int age = get_int("Age?"); | ^~~~~~~ d:/mingw/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\AbdoMAD\AppData\Local\Temp\ccTefKbe.o:0.c:(.text+0x15): undefined reference to `get_int' collect2.exe: error: ld returned 1 exit status ,但是有get_int 但是当我使用它并且代码是

GetInt

它返回

#include <stdio.h>
#include <cs50.h>


int main(void)
{
    printf("Age?")
    int age = GetInt();
    int days=age*365;
    printf("Your age is %i which means that you are %i days old", age, days);
}

在VS代码中使用get_int或至少使用GetInt应该怎么做?

1 个答案:

答案 0 :(得分:2)

如果您想要get_int,请不要写GetInt

如果您使用https://sandbox.cs50.io,则可以执行以下操作:

gcc 0.c -lcs50 -o 0

您的第一个代码将起作用。

要获取更多信息,请尝试使用Google搜索“ C链接到库”。