int A(const char* name){
name = "Here you GO!";
char* new_name;
//strcpy(new_name,name);
new_name = const_cast<char *>(name);
printf("%s\n", new_name);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这是我正在测试的源代码.
一个问题是,当我使用时const_cast<char *>,它说它是未声明的.(我知道它可以在'g ++'编译下工作)另一个问题是当我尝试strcpy将它们组合在一起时,它会弹出分段错误.前提是我必须gcc whatevername.c -std=c99用来编译.
有人提出一些建议如何解决这个问题.非常感谢..
我遇到了包含头文件的问题sys/type.h.当我使用编译g++或gcc filename.cpp它总是显示错误:sys/type.h, no such a file or directory.非常困惑.有人能帮我吗?
#include<stdio.h>
#include<sys/type.h>
#include<unistd.h>
int main()
{
pid_t child_pid;
printf("the main program ID is %d\n", (int)getpid());
child_pid = fork();
if (child_pid != 0) {
printf("This is the parent process, with id %d\n",
(int)getpid());
printf("the child's process ID is %d\n", (int)child_pid);
} else {
printf("this is the child process, with id %d\n",
(int)getpid());
}
}
Run Code Online (Sandbox Code Playgroud)