English 中文(简体)
产出数据与投入数据不相同
原标题:Output data not the same as input data
  • 时间:2012-01-15 18:25:07
  •  标签:
  • c++
  • io

我做一些 file子,并做了以下测试,但我觉得是试射。 txt与测试数据相同。 之后的 t?

试验数据:

some plain
    text
 data with
 a  number
42.0

测试产出2.txt (在有些编辑中,它有条理,但在另一些编辑中,则有一条线。)

some plain
਍ऀ琀攀砀琀ഀഀ
 data with
਍ 愀  渀甀洀戀攀爀ഀഀ
42.0  

int main()
{
    //Read plain text data
    std::ifstream filein("testinputdata.txt");
    filein.seekg(0,std::ios::end);
    std::streampos length = filein.tellg();
    filein.seekg(0,std::ios::beg);
    std::vector<char> datain(length);
    filein.read(&datain[0], length);
    filein.close();

    //Write data
    std::ofstream fileoutBinary("testoutput.dat");
    fileoutBinary.write(&datain[0], datain.size());
    fileoutBinary.close();

    //Read file
    std::ifstream filein2("testoutput.dat");
    std::vector<char> datain2;
    filein2.seekg(0,std::ios::end);
    length = filein2.tellg();
    filein2.seekg(0,std::ios::beg);
    datain2.resize(length);
    filein2.read(&datain2[0], datain2.size());
    filein2.close();

    //Write data
    std::ofstream fileout("testoutput2.txt");
    fileout.write(&datain2[0], datain2.size());
    fileout.close();
}
最佳回答

在我方工作罚款,即管理VC++方案。 6.0 并核对表和MS Word的产出。 您可以具体说明你们面临问题的编辑名称。

问题回答

页: 1 <char>/code> 数据类型只使用窄体,我的猜测是,在UTF-8或UTF-16编码编码中,可以保存经你重读的文本文档。

使用<代码>wchar_t 而是您的类型。 具体针对的是“全局”(或统法协会编码)特性。

Thou 核实甲状腺投入是成功的! 虽然你可以这样说,但你还应指出,档案中的tes数目与读写的品数没有直接关系:其特征可能不如tes(根据使用UTF8号编码的多种异构体的统法协会编码特性)或反之(尽管后者与统法协会编码系统的任何编码无关)。 各位的经验是,read(>>sn t 改为与你要求其阅读但write(> happily写道你给它的信。





相关问题
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?

热门标签