我正在做一些教程,我看到这个shell命令:
find / -name foo 2>/dev/null
Run Code Online (Sandbox Code Playgroud)
最后一个令牌是做什么的?具体来说,2?我得到>重定向将shell输出发送到文件,但是如何find只获取错误消息?
当我同时声明时,vscode无法编译文件,并且出现错误日志:
> Executing task: C:\mingw64\bin\gcc.exe -g d:\CODES\C++\try\main.cpp -o d:\CODES\C++\try\main.exe <
C:\Users\16337\AppData\Local\Temp\ccqDR0fO.o: In function `__tcf_0':
C:/mingw64/lib/gcc/x86_64-w64-mingw32/7.3.0/include/c++/iostream:74: undefined reference to `std::ios_base::Init::~Init()'
C:\Users\16337\AppData\Local\Temp\ccqDR0fO.o: In function `__static_initialization_and_destruction_0':
C:/mingw64/lib/gcc/x86_64-w64-mingw32/7.3.0/include/c++/iostream:74: undefined reference to `std::ios_base::Init::Init()'
collect2.exe: error: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)
我的代码很简单:
#include <iostream>
#include <stdio.h>
int main()
{
printf("print something");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
Dev-C ++可以正确编译该代码。
如果删除#include <iostream>,则可以正确编译。
如果字符串没有NUL字符(\ 0)并且编译器将其传递,例如带有警告,该怎么办?它对计算机和程序有何影响?
我不明白为什么在这里我的字符没有被复制,strlen是正确的但我输出了'\n'
char *my_strdup(char *str)
{
char *new_str;
char *to_copy;
int i;
to_copy = str;
i = strlen(str + 1);
new_str = malloc(sizeof(*new_str) * i + 1);
while(i - 1 > 0)
{
*new_str = *to_copy;
new_str++;
to_copy++;
i--;
}
return(new_str);
}
Run Code Online (Sandbox Code Playgroud)
这是我的测试功能:
int main()
{
char *str;
str = my_strdup("helloo");
printf("%s\n", str);
}
Run Code Online (Sandbox Code Playgroud)