...

View Full Version : 3 Q's regarding C++



Code Wizard
04-17-2004, 06:29 PM
Question:
1.The DOM is an API,and JavaScript is most widely used to access it,but in general it can be used by any language.
How can I access a browser's (IE) DOM API with C++ ?


2.In C++ struct`s are generally used as data-only classes (no functions - methods).But what if I want my struct's
members to have a default value (I'll need a constructor function,but remember,I want my struct to be data-only).
struct Test
{
int myInt=5;
};


3.Can anyone explain what binary files differ from normal text files,in most books,you find ways to use them,but
no one explains the differences...

weronpc
04-18-2004, 01:02 AM
3.Can anyone explain what binary files differ from normal text files,in most books,you find ways to use them,but
no one explains the differences...

I don't knwo the first 2,
When you write code, you write it in a text editor, that's a text file for human eyes to read.

then you compile the text file into binary file, for computer to read.

example in java, you write java code and save it as *.java, after you compile the java file, you willl get *.class, if you want to run you program, you have to use the *.class because that what computer understand, if you want to show the code to someone, you have to use the *.java because that's what human understsand

shmoove
04-18-2004, 08:26 AM
2. As far as I know, modern day C++ allows for member functions in structs. I don't know if they have constructors though, since it's been a while since I messed with C++. I'd say just try it.
Even if they don't, you can always use a class instead that only has public data members, and a constructor. Believe me, the computer won't care.

shmoove


"allows for member function in structs", forgot to write "in structs" :P

Code Wizard
04-18-2004, 09:00 AM
3.Can anyone explain what binary files differ from normal text files,in most books,you find ways to use them,but
no one explains the differences...

I don't knwo the first 2,
When you write code, you write it in a text editor, that's a text file for human eyes to read.

then you compile the text file into binary file, for computer to read.

example in java, you write java code and save it as *.java, after you compile the java file, you willl get *.class, if you want to run you program, you have to use the *.class because that what computer understand, if you want to show the code to someone, you have to use the *.java because that's what human understsand

Yes...I was speaking more of the files you can read/write from, with the special functions made for binary files - read() and write().
You have to open a file as binary (ios::binary),and also,you can only write a single type of data in each file.
So,plain text files have ASCII characters,while binary files are a succesion of 1's and 0's.
Doesn't that mean that they're just simple text files,converted in binary ...?

*A little confused here...*

shmoove
04-18-2004, 09:32 AM
If the binary in them is ASCII code (or any other kind of text encoding), then yes.
But the main difference, is that if you write 123 into a a file in binary mode, then the succession of 0's and 1's that represent the number 123 will be written into the file, and if you do it in text mode, the succession of 0's and 1's that represent the ASCII codes (again, it doesn't have to be ASCII, it could be another form of text encoding) of the digits '1', '2' and '3' will be written into the file. The same goes for reading: in text mode the information will be taken as if it represented some text-encoding, and in binary mode as just plain numbers.

shmoove

Mhtml
04-18-2004, 02:23 PM
C++ classes do have contructors and destructors.

shmoove
04-18-2004, 03:40 PM
C++ classes do have contructors and destructors.
And like I was trying to say, structs in modern day C++ are the same as classes, except that their members have public access by default, where in classes members have private access by default.
(well, I fixed the post now).

shmoove

me'
04-22-2004, 08:09 PM
Actually answering 2, the easiest way is using the constructor initialization list (or whatever it's called):
class X { //i prefer using class to struct
int i;
public:
X() : i(5) {};
}

Unit
04-22-2004, 09:36 PM
1) The only way to access DOM using C++ code is to write a plugin for the browser you are interested in. This assumes a great deal of knowledge both about how the browser exposes its DOM, and how the plugin interface works.

2) If you are using a structure only to store data, then the data does not have any inherent characteristics.. otherwise you would have used a class in the first place. So its better to initialize the structure to the default values in the same function you are initializing the structure.

3) as shmoove was saying, if you write the number(word) 123 to a file,
binary file look like this
00000000 01111011 ---> 123
text file(ASCII) looks like this
00110001 00110010 00110011 -> 49('1') 50('2') 51('3')

As you can see, in the first case, the number is represented as a whole, the true representation in binary. note that the order of bytes may vary depending on the architecture of the computer.

In the second case, the ascii code of each digit of the number is represented in binary.

Mhtml
04-23-2004, 05:48 PM
When you create a struct though, you can do like --

typedef struct{

int i,j,m;

}myStruct, *myStructPtr;

myStruct ms = {0,0,0};

That can save some time.

liorean
04-23-2004, 08:41 PM
As for #1: <http://msdn.microsoft.com/library/default.asp?url=/workshop/browser/prog_browser_node_entry.asp>

bergner
04-27-2004, 10:04 AM
Programming the browser seems rather redundant. There are many excellent DOM based libraries out there (mostly for XML, but XML and DOM go hand-in-hand).

You can have constructors and any kind of methods in a C++ struct. As long as you don't use any virtual functions (including a virtual destructor) the C++ standard guarantees bit-level compatibility with C.

The only difference between binary and text files is that M$ decided to make a difference between them and have I/O routines fiddle with the line breaks on text files. Personally I don't see any reason for doing this. It only makes it harder to write cross-platform programs, but that seems to be the M$ way...

Mhtml
04-27-2004, 10:26 AM
Constructors/Destructors/member functions in a struct? Really?

I'll have to try this..

Keermalec
04-28-2004, 09:25 PM
1. Don't know...

2. As far as I can tell, structs are identical to classes in every way (ie they can have functions, destructors etc) except that in a struct each member is publc by default, whereas in a class you have to define whether it is public or private.

3. In an ASCII file each character is coded in 8 bits according to the ASCII table (for example, 1 is 0011111, 2 is 01000000, 3 is 01000001). In a binary file you get a bunch of 1's and 0's and you have to know if you read them in as ints, floats, chars or whatever.

For example, the number 123.456 in a text file will occupy 7 bytes (7 characters) but in a binary file only 4 bytes (1 float).

:)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum