问题描述
你好,
i有一个java应用程序,用于构建特定文件格式的xml
,反之亦然。
我已经被要求将其转换为c ++,但我不是c ++的专家,
实际上我只是初学者你可以说。
i虽然有几个问题:
1-是否有任何等同于java'的流
类(ByteArrayInputStream,InputStreamRedare,Dat aInputStream ..)
2-如何打开一个在c ++中的字节(char)数组上流,以便
将其作为文本读取。我有一个字节数组,我需要从中删除一些字节
然后将其传递给文本流。
3-我知道字符串以''\结尾0''c ++中的空字符。
fil我要解析,xml-to-be-elements用''\0''分隔,怎么可以
i将读取的文本拆分为字符串,使用''\0''作为我的分隔符,而不是让b / b混淆c ++。
4-最重要的:如何解析和用c ++构造xml,
那里有api for which以及在哪里找到它?
5-最后一个坚果不是最不重要的,因为我的目标是Windows,它会是什么? />
更好地使用非托管Visual C ++。它是否有类型我需要b $ b寻找,并且它能否轻松完成任务?
哦,我使用g ++ for windows。
谢谢
问候
hello,
i have a java app that constructs an xml from a specific file format
and vice versa.
i''ve been asked to convert it to c++, but im not an expert in c++,
actually im mere beginner you can say.
i got a couple of questions though:
1- is there any equivalent to java''s Stream
classes(ByteArrayInputStream,InputStreamRedare,Dat aInputStream ..)
2- how to open a stream on a byte ( char) array in c++ in order to
read it as text. i have a byte array i need to strip off some bytes
from and then pass it to a text stream.
3- i know strings are ended in ''\0'' the null character in c++.in the
fil i want to parse, xml-to-be-elements are separated by ''\0'', how can
i split the read text into strings using ''\0'' as my delimiter without
confusing c++.
4- the most important : how to parse and construct xml in c++, is
there any api for that and where to find it?
5- last nut not least , since im targetting Windows , would it be
better to use unmanaged Visual C++ . does it have the types i am
looking for,and does it make it easy to accomplish the task ?
oh and i use g++ for windows.
Thanks
regards
推荐答案
我不确定这是一个公平的第一工作。
I am not sure that is a fair "first" job.
是。对于格式化的IO,您可能需要std :: ofstream。对于
unformatted / binary,你可以使用streambuffer或C文件
iosystem。你最好研究一下。
Yes. For formatted IO you probably need an std::ofstream. For
unformatted/binary, you could use a streambuffer or the C file
iosystem. You better study that.
您应该阅读文档,并在此处的
问题中更具体。这并不困难,但如果没有更多的知识,我们就无法回答。
You should read the documentation and be more specific in your
question here. It''s not difficult, but we can''t answer without more
knowledge of your problem.
实际上这是假的。 C字符串以null结尾,C ++字符串
不是。
That is false, actually. C strings are null-terminated, C++ strings
are not.
这又取决于你的要求。
This again depends on your requirements.
C ++有几个不错的xml解析器。一个简短的谷歌应该给你一个候选人
。选择一个可能更多是一个政治决定
由贵公司制作。
There are several nice xml-parsers for C++. A short google should give
you a candidate. Choosing one probably is more of a political decision
to be made by your company.
只有一个C ++ - 即我们在这个
新闻组中讨论的语言。微软已经创建了一种新语言,它可以用于某些原因调用托管C ++,但它不是C ++。 托管C ++可能
可能是编程的好语言,但它不能用于移植到C ++的
。
/ Peter
There is only one C++ - namely the language we discuss in this
newsgroup. Microsoft has created a new language which they for some
reason call "managed C++", but it is not C++. "Managed C++" might
likely be a fine language for programming, but it can''t be used for
porting to C++.
/Peter
我不确定这是一个公平的第一工作。
I am not sure that is a fair "first" job.
是的。对于格式化的IO,您可能需要std :: ofstream。
Yes. For formatted IO you probably need an std::ofstream.
(你的意思是std :: ifstream吗?)
(did you mean std::ifstream ?)
更容易使用其中一个std :: ifstream :: get()函数,或者更好
std :: ifstream :: read ();但您可能不需要使用未格式化的输入 - 请参阅
以下。
Easier to use one of the std::ifstream::get() functions, or better
std::ifstream::read(); but you may not need to use unformatted input - see
below.
您应该阅读文档,并在此处的
问题中更具体。这并不困难,但如果没有更多的知识,我们就无法回答。
You should read the documentation and be more specific in your
question here. It''s not difficult, but we can''t answer without more
knowledge of your problem.
实际上这是假的。 C字符串以null结尾,C ++字符串
不是。
That is false, actually. C strings are null-terminated, C++ strings
are not.
更确切地说:C ++字符串类std :: string可能不是使用以null结尾的字符数组实现的
(标准没有
需要这个。)
To be more precise: the C++ string class std::string is probably not
implemented using null-terminated character arrays (the standard does not
require this).
也许您可以使用std :: getline()指定''\0''作为分隔符来阅读
你的xml元素直接进入std :: string'。你不会混淆C ++那种方式,你不必乱用内存管理,你的
元素最终会得到很好的C ++风格的字符串。
/.../
-
Lionel B
Perhaps you could use std::getline() specifying ''\0'' as delimiter to read
your xml elements straight into std::string''s. You won''t confuse C++ that
way, you won''t have to mess around with memory management and your
elements end up in nice C++-style strings.
/.../
--
Lionel B
[snip]
[snip]
(你的意思是std :: ifstream?)
(did you mean std::ifstream ?)
是的。
Yup.
更容易使用其中一个std :: ifstream :: get()函数,或者更好
std :: ifstream :: read ();但您可能不需要使用未格式化的输入 - 请参阅下面的
。
Easier to use one of the std::ifstream::get() functions, or better
std::ifstream::read(); but you may not need to use unformatted input - see
below.
什么是更容易要看。我在C ++中使用二进制IO的经验已经是一个分层的C文件io,用于简单的IO作业,因为OP具有
或者转向金属。对于具有高性能要求的IO(或者说b
大文件:据我所知,MSVC仍然只支持文件的IO
到2GB)。
[snip]
What is "easier" depends. My experience with binary IO in C++ has
either been a layered above C file io for simple IO jobs as the OP has
or going "to the metal" for IO with high performance requirements (or
large files: so far as I know MSVC still only supports IO for files up
to 2GB).
[snip]
实际上这是假的。 C字符串以null结尾,C ++字符串
不是。
That is false, actually. C strings are null-terminated, C++ strings
are not.
更确切地说:C ++字符串类std :: string可能不是使用以null结尾的字符数组实现的
(标准没有
要求这个)。
To be more precise: the C++ string class std::string is probably not
implemented using null-terminated character arrays (the standard does not
require this).
该标准允许嵌入空值并且还有其他要求
禁止std :: string实现为以null结尾的
string。
[snip]
/ Peter
The standard allows embedded nulls and also has other requirements
that forbids std::string to be implemented as a null-terminated
string.
[snip]
/Peter
这篇关于需要帮助将java转换为c ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!