473,626 Members | 3,948 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

need help converting java to c++

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(ByteArr ayInputStream,I nputStreamRedar e,DataInputStre am ..)
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

Feb 13 '07 #1
12 2678
On 13 Feb., 12:17, "steven acer" <dudest...@gmai l.comwrote:
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 am not sure that is a fair "first" job.
i got a couple of questions though:
1- is there any equivalent to java's Stream
classes(ByteArr ayInputStream,I nputStreamRedar e,DataInputStre am ..)
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.
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.
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.
3- i know strings are ended in '\0' the null character in c++.
That is false, actually. C strings are null-terminated, C++ strings
are not.
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++.
This again depends on your requirements.
4- the most important : how to parse and construct xml in c++, is
there any api for that and where to find it?
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.
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.
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

Feb 13 '07 #2
On Tue, 13 Feb 2007 04:00:26 -0800, peter koch wrote:
On 13 Feb., 12:17, "steven acer" wrote:
>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 am not sure that is a fair "first" job.
>i got a couple of questions though:
1- is there any equivalent to java's Stream
classes(ByteAr rayInputStream, InputStreamReda re,DataInputStr eam ..)

Yes. For formatted IO you probably need an std::ofstream.
(did you mean std::ifstream ?)
For unformatted/binary, you could use a streambuffer or the C file
iosystem. You better study that.
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.
>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.
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.
>3- i know strings are ended in '\0' the null character in c++.
That is false, actually. C strings are null-terminated, C++ strings
are not.
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).
>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++.
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
Feb 13 '07 #3
On 13 Feb., 13:48, Lionel B <m...@privacy.n etwrote:
On Tue, 13 Feb 2007 04:00:26 -0800, peter koch wrote:
On 13 Feb., 12:17, "steven acer" wrote:
[snip]
Yes. For formatted IO you probably need an std::ofstream.

(did you mean std::ifstream ?)
Yup.
>
For unformatted/binary, you could use a streambuffer or the C file
iosystem. You better study that.

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.
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]
3- i know strings are ended in '\0' the null character in c++.
That is false, actually. C strings are null-terminated, C++ strings
are not.

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).
The standard allows embedded nulls and also has other requirements
that forbids std::string to be implemented as a null-terminated
string.

[snip]

/Peter

Feb 13 '07 #4
Thanks for the replies guys.
first i dont wanna study and delve into c++ because im a java
developer and im doing this conversion for *just 1 time*.besides it's
a really small app.so any help i can get is really appreciated.
ok let's see
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).
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.
i think you got me wrong . i have a .trs(whatever) file which i want
to read and generate an xml based upon its contents.
in this file i have data separated by null characters, in java i would
have done read the contents of the trs file into a string
and then myString.split( "\0") would return me an array of tokens.is
there anything similar in c++ to split a string using a
delimiter( since strings do not end with "\0" no problem).

regarding question 2:
=============== ======
>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.
an example of java code would clear things up : BufferedReader in=new
BufferedReader( new InputStreamRead er(new ByteArrayInputS tream(data)));
data is an array of bytes (char). at the end of this statement i would
be reading text characters.that is what i meant by opening a text
stream on a byte array.can this be done in c++?
1 more thing is there a way to copy an array to another in c++ other
then looping through the array ?

thanks alot

Feb 13 '07 #5
On Tue, 13 Feb 2007 07:12:03 -0800, steven acer wrote:

[snip]
>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.

i think you got me wrong .
Not necessarily. Read on.
i have a .trs(whatever) file which i want
to read and generate an xml based upon its contents.
in this file i have data separated by null characters, in java i would
have done read the contents of the trs file into a string
and then myString.split( "\0") would return me an array of tokens.is
there anything similar in c++ to split a string using a
delimiter( since strings do not end with "\0" no problem).
Code snippet off the top of my head (not tested!):

#include <ifstream>
#include <string>
#include <vector>

ifstream ifs(your_trs_fi le);
if (!ifs) ... // handle file open failure

std::string str;
std::vector<std ::stringtoken;
while (!getline(ifs,s tr,'\0')) token.push_back (str);

now token[i] is the i-th token from your file.

[snip]

--
Lionel B
Feb 13 '07 #6
#include <ifstream>
#include <string>
#include <vector>

ifstream ifs(your_trs_fi le);
if (!ifs) ... // handle file open failure

std::string str;
std::vector<std ::stringtoken;
while (!getline(ifs,s tr,'\0')) token.push_back (str);

now token[i] is the i-th token from your file.
all right i was not that far , but what about consecutive nulls like
'\0\0' ?

i've googled for a c++ xml parser and found apache's xercesc-c++
(kinda like SAX), but it just parses xml as i've seen,do you know of
any that constructs or transforms xml ?

one more silly question - *sorry found nothing about it on the web* -
how to make c++ ( or the preprocessor) find the following include
#include <xercesc/dom/DOM.hpp- or any other
does it have to point to some file on my filesystem , how does c++
look for it?
and regarding byte arrays, any suggestions ?
many thanks
Feb 13 '07 #7
steven acer wrote:
>
i've googled for a c++ xml parser and found apache's xercesc-c++
(kinda like SAX), but it just parses xml as i've seen,do you know of
any that constructs or transforms xml ?
I though xerces did that too.
>
one more silly question - *sorry found nothing about it on the web* -
how to make c++ ( or the preprocessor) find the following include
#include <xercesc/dom/DOM.hpp- or any other
does it have to point to some file on my filesystem , how does c++
look for it?
C++ does not specify how the file is found. That depends on your
compiler. Consult your compiler docs.
and regarding byte arrays, any suggestions ?
In C++ you would use an std::istringstr eam which is a stream that reads
from a string, you would need to convert you byte array into a string
first. Simple enough unless you have character encoding issues (you seem
to use byte and char interchangeably so I'm not sure exactly what you need).

>
many thanks

john

Feb 13 '07 #8
On Tue, 13 Feb 2007 08:46:54 -0800, steven acer wrote:
> #include <ifstream>
#include <string>
#include <vector>

ifstream ifs(your_trs_fi le);
if (!ifs) ... // handle file open failure

std::string str;
std::vector<std ::stringtoken;
while (!getline(ifs,s tr,'\0')) token.push_back (str);

now token[i] is the i-th token from your file.

all right i was not that far , but what about consecutive nulls like
'\0\0' ?
Well, how do you want to treat them? If there's nothing between delimiters
('\0' in this case) you will end up with a token comprising an empty
string; i.e. a string containing no characters, or of length zero, if you
like.

[...]
and regarding byte arrays, any suggestions ?
I'ts not clear to me what you want "byte arrays" *for* so it's difficult
to suggest anything... C++ certainly has arrays and I suspect that "byte"
probably translates to the C++ "char" type. But if all you want is
something that behaves like a string of characters then std::string is the
way to go. If you want to do formatted I/O with strings then you might
look at std::stringstre am.

--
Lionel B
Feb 13 '07 #9
I though xerces did that too.
can you please show me a small example of writing xml to a file.
C++ does not specify how the file is found. That depends on your
compiler. Consult your compiler docs.
i did . i'm usig g++ for windows.it says to use the -
I<include_files _diretoryoption while compiling.
but it did not work !
it just could not find the files
i have in my header file
#include <xerces/dom/DOM.hpp>
on the command line typing : -Ic:\includes as an option for g++ never
works though the hierarchy xerces\dom\DOM. hpp is in c:\includes.
im starting to think i need an IDE for this small task.
do you know of any free IDE that provies intelliscence help, i'm using
the CDT plugin for eclipse but it's ot much of an environment.

Feb 14 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2125
by: William Krick | last post by:
I've been given the task of converting some existing java code to PHP so we can integrate it into our web based product. The problem I'm facing is that the java code makes heavy use of Vector objects to hold data. This in itself isn't a problem however the java code makes heavy use of Vector.insertElementAt(). This method inserts into the vector container at a desired location and shifts the indexes of all the other items accordingly...
2
3397
by: nanookfan | last post by:
Hi all, I'm having a bizarre problem converting XML files to HTML using an XSLT. The problem is only occuring in my Netscape 7.0 browser. What makes it more bizarre is that it is only happening when I put my XML files and the .xsl files on my ISP's system for my home page. If I try to open the XML files in Netscape 7.0 on my own machine (ie, not on the ISP's system), the pages convert file and the result is displayed in HTML.
48
3221
by: Chad Z. Hower aka Kudzu | last post by:
A few of you may recognize me from the recent posts I have made about Indy <http://www.indyproject.org/indy.html> Those of you coming to .net from the Delphi world know truly how unique and "huge" Indy is both as a project, in support, development, and use. But Indy is new to the .net world. Indy is a HUGE library implementing over 120 internet protocols and standards and comes with complete source. Its an open source project, but not...
0
1442
by: Elhanan Maayan | last post by:
hi.. so i'm slowly moving the transition to csharp and once again i'm faced with the problem for flipped hebew letters etc... but now the problem may not be so hard to solve as i have seen that the unicode.org has a java code for that algorithem, i've also seen that microsoft has jlca, java language to csharp converter, so i'm asking is it possible to use both tools to create a function
1
3488
by: singlal | last post by:
Hi, We are looking for options of converting CICS screens to a GUI application (.net, Java, etc.) to increase the usability of the screens. We would like to keep the underlying logic and database DB2 on OS390, but the presentation layer would be different. Some of the options are: (1) Replacing CICS screen commands to a MQ message to communicate with the front-end
9
6722
by: anupamjain | last post by:
Hi, After 2 weeks of search/hit-and-trial I finally thought to revert to the group to find solution to my problem.(something I should have done much earlier) This is the deal : On a JSP page, I want to grab a URL and parse /change the HTML and send it to the JSP page. I take the URL from the user in a textbox (not the
7
5331
helpwithcode
by: helpwithcode | last post by:
Hi people, I am just learning java.I have been creating a project which involves JDBC Connectivity.I find that the statements, String string_dob=text_dob.getText(); //Converting string to date System.out.println(string_dob); s.Info_DOB=Date.valueOf(string_dob); runs perfectly fine in the method insert() and throws up an illegal Exception in the method UPDATE.This is the error I get when I pass a date "1979-05-02"
2
4127
by: sriniwas | last post by:
Hi Frnd's, m using prefuse visulation,it's have one display class and this class have one saveImage(outPutStream, String jpg,double size);. now graph is converting ia jpg image properly.now my problem is tht,If graph is to large if it going out of screen thn ,i m getting jpg image on screen disply graph,m not getting the image of tht graph which going out of screen. this is my code This is my code
1
1510
by: icanhelp33 | last post by:
whats the best way for converting vb.net application to C#
0
8199
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8638
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8365
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8505
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7196
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6125
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4198
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1811
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1511
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.