English 中文(简体)
c_str(r)没有返回,但不是空洞
原标题:c_str() returns nothing, but string not empty

因此,我有一个班子。

class MySuperClass {
public:
 std::string buffer;
};

And wants to print buffer to std::cout. Here s some code about filling string from a file:

MySuperClass msc;
std::fstream file("./favicon.ico", std::fstream::in | std::fstream::binary);
if (file.is_open()) {
 std::stringstream ss;
 while (!file.eof())
   ss << static_cast<uint8_t>(file.get());
 msc.buffer.assign(ss.str());
 file.close();
}

当我产出扼杀时,所有ok。 它印刷了幻灯,但有些是。 但当我打电话到<代码>c_str(>>>>>>/code>并试图打印时,该编码便没有打印。

最佳回答

1 ICO文档starts with 20 bytes so buffer.c_str()各点为空洞str。 因此,它没有显示任何情况。 如果你印刷了按字母顺序排列的数值,你就会立即看到为什么。

for (const auto c: buffer)
    std::cout << std::setfill( 0 ) << std::setw(2) << std::hex << +c <<    ;

OTOHstd:string can contained 嵌入的,将整个文件编为产出流。

但是,你首先将双亲文件印成? 它是一种非常坏的想法,而且可能因为星流中可能存在控制特性而使终点站完全瘫痪,而且你在reset之前,几乎永远不会看到正常案文。 终端。 除你外,还应大街的校对数据,其速度远远快于每果园的运行。

See See See

问题回答

暂无回答




相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签