小编mue*_*slo的帖子

"to_string"不是"std"的成员?

好的,我有

tmp.cpp:

#include <string>

int main()
{
    std::to_string(0);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

但是当我尝试编译时,我得到:

$ g++ tmp.cpp -o tmp
tmp.cpp: In function ‘int main()’:
tmp.cpp:5:5: error: ‘to_string’ is not a member of ‘std’
     std::to_string(0);
     ^
Run Code Online (Sandbox Code Playgroud)

我正在运行g ++版本4.8.1.与我在那里发现的所有其他对此错误的引用不同,我没有使用MinGW,我在Linux(3.11.2)上.

任何想法为什么会这样?这是标准的行为,我做错了什么或某处有错误?

c++ linux string g++ c++11

40
推荐指数
2
解决办法
8万
查看次数

不能使用matplotlib的savefig()读写文件?

我试图将我的数字保存在临时文件中.我想以最蟒蛇的方式做到这一点.为此,我尝试使用tempfile,但我遇到了一些问题.savefig函数应该能够将文件名作为字符串或类似文件的对象,在我尝试的前两件事中我完全没有看到它.

这是我最初尝试过的:

with tempfile.TemporaryFile(suffix=".png") as tmpfile:
    fig.savefig(tmpfile, format="png") #NO ERROR
    print b64encode(tmpfile.read()) #NOTHING IN HERE
Run Code Online (Sandbox Code Playgroud)

然后我尝试了什么:

with open("test.png", "rwb") as tmpfile:
    fig.savefig(tmpfile, format="png")
    #"libpngerror", and a traceback to 
    # "backends_agg.py": "RuntimeError: Error building image"
    print b64encode(tmpfile.read()) 
Run Code Online (Sandbox Code Playgroud)

然后我尝试了什么:

with open("test.png", "wb") as tmpfile:
    fig.savefig(tmpfile, format="png")

with open("test.png"), "rb") as tmpfile:
    print b64encode(tmpfile.read())
Run Code Online (Sandbox Code Playgroud)

这有效.但现在使用模块tempfile的全部意义已经消失,因为我必须自己处理命名和删除tempfile,因为我必须打开它两次.有什么方法可以使用tempfile(没有奇怪的解决方法/黑客攻击)?

python matplotlib temporary-files python-2.7

3
推荐指数
1
解决办法
1500
查看次数

标签 统计

c++ ×1

c++11 ×1

g++ ×1

linux ×1

matplotlib ×1

python ×1

python-2.7 ×1

string ×1

temporary-files ×1