|
std::vector<std::string> .
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
See you after long time Joaquin.
Thanks.
Mazy
No sig. available now.
|
|
|
|
|
anyone know it? thank you?
|
|
|
|
|
Good people,
How do I set the “Comment” attribute of a file or folder using VB script ?
For example, the following code lists “Comment” attributes for files under C:\ directory:
set shell = CreateObject("Shell.Application")
set folder = shell.namespace("C:\")
for each folderitem in folder.items
list = list & _
folder.GetDetailsOf(folderitem , 0) & ", " & _
folder.GetDetailsOf(0, 5) & ": " & _
folder.GetDetailsOf(folderitem, 5) & vbCr
next
MsgBox list
Thanks,
Serge
|
|
|
|
|
I also do not understand what does macro guard do in header
file. What do we need to include #ifndef, # define and #endif.
And why do they capitialize the COUNTER_H, is COUNTER_H the
file name? It seems to be. Why is it called macro guard?
----------------------------
// File: Counter.h
// Counter class definition
#ifndef COUNTER_H // used to avoid multiple definitions
#define COUNTER_H // not part of the class
class counter
{
public:
// Member Functions
// Constructors
private:
// Data members (attributes)
};
#endif // COUNTER_H
|
|
|
|
|
It ensures that a declaration can only be included once.
Put simply, if you didn't have it in, you could end up with two versions of the same thing linked into your code. Try it. You won't get a compiler error but you will get a linker error
|
|
|
|
|
You can have compiler errors too. like the “type redefinition” one.
|
|
|
|
|
Regarding the symbol name, it is just a convention to use something that resembles the file name, for readability. It is always capitalized to avoid name collisions - language keywords are never all capitals, and #defines and typedefs are never named after files.
--Mike--
Latest blog entry: *drool* (Alyson) [May 10]
Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber
"You have Erica on the brain" - Jon Sagara to me
|
|
|
|
|
Capitalisation does not avoid name collisions. Example:
_DEBUG
The compiler defines _DEBUG when you specify the /MTd or /Mdd option. These options specify debug versions of the C runtime library.
Use GUID or MS-specific #pragma once.
|
|
|
|
|
1.) If Classes in C++ can do anything Structs do plus
more, why do we still have Structs in C++? Is there
something Classes can't do but Structs? Do you
prefer Classes over Structs?
2.) I understand the difference between Classes and
Structs is the default asscess of the Structs is public,
and Classes is private. But I don't understand why do we
use private. I know that the private keyword specifies
that those members are accessible only from member functions
and friends of the class. But why do we use it? Any specific
example? Why do we want to limit those asscess?
|
|
|
|
|
VW_Red_Jetta wrote:
why do we still have Structs in C++?
The reason is to maximise the compatibility with C. C has structs, and the default access level is public, so C++ retains the same system.
VW_Red_Jetta wrote:
But I don't understand why do we use private.
C++ additionally allows classes, and specifies that good encapsulation / good OOP the default access should be private. This ensures that anyone who needs to get/set the properties of a private variable will have to use an accessor or a mutator method. In general, you need to modify the properties of an object via getXXX() and setXXX() methods.
As a rule of thumb, use structs for POD, Plain Old Data (anything without pointers, that doesn't need initialisation or special procudures for copying). Use classes when you need to have your class DO something, rather than just store information.
|
|
|
|
|
[quote] As a rule of thumb, use structs for POD, Plain Old Data (anything without pointers, that doesn't need initialisation or special procudures for copying). Use classes when you need to have your class DO something, rather than just store information. [/quote]
Okay, so can we simply just use classes through all of the C++ programs?
Do the real world programmers use structs and classes together? Since
the existence of structs is for the backward compatibility of C language,
and Classes can do anything Structs do, so why not just use classes?
I second this question: Do the real world programmers use structs and classes together?
Thanks.
|
|
|
|
|
VW_Red_Jetta wrote:
I second this question: Do the real world programmers use structs and classes together?
Yes, look an any real API and you'll find some structs. Generally I try to avoid them, unless you're sending a very strong message about the complexity of the object.
DirectX for example.
In DirectX struct is used to signify that objects (especially the vertices of polygons) can be memcpy()'d directly. This is used almost to speed up the process of adding to the vertex buffer.
Not that I'd generally cite DirectX as a API for demonstrating good programming practices, but it's appropriate in this situation.
|
|
|
|
|
VW_Red_Jetta wrote:
Do the real world programmers use structs and classes together?
Yes, in fact I wrote two struct s today. Yes, you could use all classes, there is no rule against that. However for readability sake, I use a struct when it's just a group of data, with no methods outside of a constructor to init the data to 0 or some other default.
--Mike--
Latest blog entry: *drool* (Alyson) [May 10]
Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber
"You have Erica on the brain" - Jon Sagara to me
|
|
|
|
|
Hi,
Just wondering if anyone knows how to write a program which can automatically install a device driver(from .inf) file into the OS.
Thanks
|
|
|
|
|
I've got a datafile to read from a mainframe system.
It's got data store in the bits of each byte.
I want to be able to define a struct to extract the bits so I can optimize the bitshiting operations I have to do (It's a big file).
I can't find anything that shows how to define a struct to anything lower than a BYTE.
Please help.
typedef struct ffStockData
{
BYTE fBucketCount;
// I need to be able to expand this to 2 values per 1 byte
BYTE ffFiller[104];
} FFSTOCKDATA, *PFFSTOCKDATA;
|
|
|
|
|
// Try this:
#include "stdafx.h"
struct Bits
{
unsigned m_1stBit:1;
unsigned m_2ndBit:2;
unsigned m_3rdBit:3;
};
int main(int argc, char* argv[])
{
Bits myBits;
myBits.m_1stBit = 1;
myBits.m_2ndBit = 0;
myBits.m_3rdBit = 1;
printf("size of the myBits is: %d\n", sizeof(myBits));
printf("myBits.m_1stBit = %d\n", myBits.m_1stBit);
printf("myBits.m_2ndBit = %d\n", myBits.m_2ndBit);
printf("myBits.m_3rdBit = %d\n", myBits.m_3rdBit);
return 0;
}
|
|
|
|
|
Serge Krynine wrote:
struct Bits
{
unsigned m_1stBit:1;
unsigned m_2ndBit:2;
unsigned m_3rdBit:3;
};
That is incorrect, the number after the colon is how many bits to use for that variable, so that struct uses 6 bits total, not 3. The correct code is:
struct Bits
{
unsigned m_1stBit:1;
unsigned m_2ndBit:1;
unsigned m_3rdBit:1;
};
--Mike--
Latest blog entry: *drool* (Alyson) [May 10]
Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber
"You have Erica on the brain" - Jon Sagara to me
|
|
|
|
|
|
Actually, you should declare your struct with padding out to the width of the datatype that you declare as the bits. EX:
struct Bitflags
{
unsigned char Bit1 : 1;
unsigned char Bit1 : 1;
unsigned char Bit1 : 1;
unsigned char Padding : 5;
};
|
|
|
|
|
I need to 'tag' a binary file I generate with a key value. I can't change the file format since a third-party vendor is using the output. I remember a Win32 class I took long ago where there was a way to write info to an NTFS file separate from it's data, almost like a file namespace. Anyone know how to do this?
I found more info:
Using the optional "named" attributes.
From a console window do this: echo some_guid_key_string > test.txt:key
How to read/write the named key data attribute from a fstream or hFile?
|
|
|
|
|
You found the answer, they're called streams. You can use a ":streamname" construct with any API that takes a file name. So you could open the file called "yourdatafile:mystream" and then any reads/writes you do are directed to that stream.
--Mike--
Latest blog entry: *drool* (Alyson) [May 10]
Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber
"You have Erica on the brain" - Jon Sagara to me
|
|
|
|
|
Ok, I'm making a file converter for a legacy app and it formats it's numbers lamely.
i.e.:
Normal c++ format:
1.5625E-002
Lame legacy app:
0.15625E-01
So I have 2 options: 1. Find the right format options, or 2. Split the number (represented in a std::string) @ the E and divide the ffirst half by 10, and add 1 to the exponent.
Now my question is:
A. Is there an easy way to format the number? (Lame Legacy format)
B. How do I easily split a std::string without going through all kinds of tepm assignments and sorry hoops?
- Nitron
"Those that say a task is impossible shouldn't interrupt the ones who are doing it." - Chinese Proverb
|
|
|
|
|
I think the following can do the trick:
#include <iostream>
#include <string>
#include <stdio.h>
std::string legacy_display(double x)
{
char buff[256];
sprintf(buff,"%.4lE",x);
int integer_part;
int fractional_part;
int exponent;
sscanf(buff,"%d.%dE%d",&integer_part,&fractional_part,&exponent);
if(integer_part>=0){
sprintf(buff,"0.%d%.4dE%+.2d",integer_part,fractional_part,exponent+1);
}else{
sprintf(buff,"-0.%d%.4dE%+.2d",-integer_part,fractional_part,exponent+1);
}
return buff;
}
int main()
{
std::cout<<legacy_display(1.5625E-002)<<std::endl;
std::cout<<legacy_display(1.5625E+005)<<std::endl;
std::cout<<legacy_display(0.0)<<std::endl;
std::cout<<legacy_display(1.0)<<std::endl;
std::cout<<legacy_display(-1.0)<<std::endl;
return 0;
}
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thanks Joaquín !
- Nitron
"Those that say a task is impossible shouldn't interrupt the ones who are doing it." - Chinese Proverb
|
|
|
|