小编Dan*_*mas的帖子

为什么此代码使用带字符串的映射(C++)会出现运行时错误?

为什么这段代码有运行时错误?

#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,则会产生运行时错误.我该如何纠正?谢谢!

c++ string printf stl map

6
推荐指数
1
解决办法
2084
查看次数

如何在log(n)时间内在数组的任何范围内找到最大值?

例如阵列:{1,5,2,3,2,10}

范围:0-1答案:5范围:2-4答案:3范围:0-5答案:10等

c++ algorithm indexed binary-search-tree

0
推荐指数
1
解决办法
5545
查看次数

标签 统计

c++ ×2

algorithm ×1

binary-search-tree ×1

indexed ×1

map ×1

printf ×1

stl ×1

string ×1