未定义对'的引用;getchar_解锁';错误

未定义对'的引用;getchar_解锁';错误,c,linker-errors,C,Linker Errors,我试图用c编程和代码块作为IDE来解决一个codechef实践问题。我找到了一种比scanf()函数读取输入更快的方法,但当我运行程序时,我得到了错误“未定义对“getchar\u unlocked”的引用错误”。你们能告诉我我做错了什么吗?有没有其他方法可以更快地读取输入 #include<stdio.h> inline int fastread() { int noRead=0; char p=getchar_unlocked();

我试图用c编程和代码块作为IDE来解决一个codechef实践问题。我找到了一种比scanf()函数读取输入更快的方法,但当我运行程序时,我得到了错误“未定义对“getchar\u unlocked”的引用错误”。你们能告诉我我做错了什么吗?有没有其他方法可以更快地读取输入

#include<stdio.h>
inline int fastread()
{
        int noRead=0;
        char p=getchar_unlocked();
        for(; p<33;) {
                p=getchar_unlocked();
        };
        while(p>32) {
                noRead = (noRead << 3) + (noRead << 1) + (p - '0');
                p=getchar_unlocked();
        }
        return noRead;
};
unsigned int gcd(unsigned int a, unsigned int b)
{
    if (b == 0)
       return a;
    else
       return gcd(b, a % b);
}
int main()
{
    int t,i,answer=0;
    unsigned int n;
    t = fastread();
    while(t--)
    {
        n = fastread();
        unsigned int a[n];
        for(i=0;i<n;i++)
            a[i]=fastread();
        answer = gcd(a[0],a[1]);
        for(i=2;i<n;i++)
            answer = gcd(a[i],answer);
        printf("%u\n",answer);
    }
    return 0;
}
#包括
内联int快速读取()
{
int-noRead=0;
char p=getchar_unlocked();
对于(;第32页){
noRead=(noRead引用了关于SO的答案

getchar_unlocked在Windows中不受欢迎,因为它是线程不安全的 getchar()的版本

GeChaluxOnLoad,它与SCANF或CIN相比,开销较小,不是C或C++的标准特征,在这里,您可以始终使用GETCHARE()来使用。


或者,您可以编写一个函数getchar_unlocked(),以返回getchar()的值,用于机器测试,如果您必须在联机问题中使用它。

我认为
getchar_unlocked
在Windows中不受欢迎,因为它是
getchar()的线程不安全版本
.Sp可能是因为它在代码块库中不可用。除非速度因素非常必要,否则请尽量避免getchar_unlocked。可能有人应该问微软为什么不支持POSIX?@Jayesh这意味着我不能使用getchar_unlocked。你能建议其他更快的方法读取输入吗?@JayeshAhir我说不,你不能。但你可以使用
scanf
getchar()
读取单个字符。我认为您走错了方向。您的问题似乎不是因为输入流可能被锁定而导致输入速度慢,而是因为您正在逐字符读取。请将您的设计更改为使用
fgets
或类似工具来读取较大数据块中的数据。在任何情况下,这看起来都很像prematu重新优化。首先对性能需求和瓶颈进行详细分析。但在此之前,请进一步了解标准库提供的不同IO和字符串到数字转换函数。