下面的代码显示了分段错误。我发现的错误在哪里是它在包含 printf() 语句的行中,但不知道为什么会这样以及如何纠正它。谁能在这里帮帮我..
#include<iostream>
#include<stdio.h>
#include<string>
#include<readline/history.h>
#include<readline/readline.h>
using namespace std;
int main()
{
using_history();
string command("history");
add_history(command.c_str());
if (command == "history")
{
cout<< "hello\n";
for(int i = 0 ; i < history_length ; i++)
{
cout<<"in there\n";
HIST_ENTRY *entry = history_get(i);
cout<<"till here\n";
printf("%5d %s", i , entry->line);
}
}
return 0;
}