为什么这段代码有运行时错误?
#include <cstdio>
#include <map>
#include <string>
#include <iostream>
using namespace std;
map <int, string> A;
map <int, string>::iterator it;
int main(){
A[5]="yes";
A[7]="no";
it=A.lower_bound(5);
cout<<(*it).second<<endl; // No problem
printf("%s\n",(*it).second); // Run-time error
return 0;
}
Run Code Online (Sandbox Code Playgroud)
如果你使用cout,它工作正常; 但是,如果使用printf,则会产生运行时错误.我该如何纠正?谢谢!
例如阵列:{1,5,2,3,2,10}
范围:0-1答案:5范围:2-4答案:3范围:0-5答案:10等