|
Thanks a lot!!!
Now i want to read the file into the memory and work with this memory like i worke as with file, i think using istream, but i can't make the istream object...
Here is my code:
<br />
ifstream shapefilef(ShapeFileName.c_str(),ios::binary);<br />
shapefilef.seekg(0,ios::end);<br />
streampos ps = shapefilef.tellg();<br />
int size = ps.seekpos();<br />
char* data = new char [size];<br />
shapefilef.seekg(0,ios::beg);<br />
shapefilef.read(data,size);<br />
istream shapefile(data);
Where is the mistake? I can't compile it... Something in constructor.
|
|
|
|
|
Have a try:
istrstream shapefile(data); // you must #include <strstream>
The istream not constructor like that istream(char* ...)
I think that you need istrstream
|
|
|
|
|
Following should work.
int fh = _open(file name, _O_APPEND , _S_IREAD | _S_IWRITE );<br />
int filesize = _filelength(fh);
Above code needs following header files
1. io.h
2. fcntl.h
3. sys\stat.h
I don't now how can we get file size using ifstream.h. I used above to get it.
We Believe in Excellence
|
|
|
|
|
Or use good old stat()/_stat() Then you won't have to open and close the file. And you don't have to worry about text/binary mode.
|
|
|
|
|
Is there any way to get the object pointer through a pointer to its' member variable?
|
|
|
|
|
If you are within the scope of the class, the object pointer is always available thru keyword "this". If you are outside, then you have used some mechanism to obtain the pointer to the function of an object. This mechanism must have used the object or its pointer, therefore, in that case there is no problem of obtaining the pointer to the object.
|
|
|
|
|
outside the class
and know only one address
|
|
|
|
|
#define CK_CONTAINING_RECORD( PTR, TYP, FLD ) \
( (TYP*)( (byte*)(PTR) - (byte*)(&((TYP*)0)->FLD) ) )
class MyClass {
public:
long m_long;
};
long *lp = ...;
MyClass *op = CK_CONTAINING_RECORD(lp, MyClass, m_long);
...cmk
Save the whales - collect the whole set
-- modified at 0:26 Thursday 16th February, 2006
|
|
|
|
|
but the object is already there
|
|
|
|
|
Not safely. Only if you know the offset in memory of the member variable from the start of the class. Generally though, if you need to do this, you've got a bad design, so fix it.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
It doesn't mean you have a bad design. It can though.
In fact, usign that technique can allow you to create safer versions of such things as std::list which have all sorts of bookkeeping issues in complex system. Systems like this are common in operating systems.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
How to check whether a CArray is empty or not?
For ex: If you have a char x.
You can do if(x==NULL), then print"Error".
How can you do this kind of testing with a CArray? What is used in the place of NULL?
|
|
|
|
|
CArray::GetCount
Regards,
Nish
|
|
|
|
|
You can check it by:
CArray arr;
int i = arr.GetSize();
if(i==0)
AfxMessageBox("Empty Array");
Cheers
Ganesh
hi
|
|
|
|
|
cuteee wrote: You can do if(x==NULL), then print"Error".
what about CArray::GetSize() function
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
CArray::GetSize() function
As per my understanding if i use GetSize, i can check the size of the array. I need to check the contents of the array. How is it possible?
|
|
|
|
|
<blockquote class='FQ'><div class='FQA'>cuteee wrote:</div>CArray::GetSize() function </blockquote>
CArray is just template class... it depends on what datatype you are going to create collection. pls clear you want to check is there any element in the array or not...
Check out CArray::GetUpperBound() ,The condition GetUpperBound( ) = –1 indicates that the array contains no elements.
<p align='right'> <small>"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow</small></p>
cheers,
<a target=_blank href="http://alok.bizhat.com"> Alok Gupta </a>
VC Forum Q&A :- <a href="http://www.codeproject.com/tips/cppfaq10dec04-23jan05.asp" target=_blank>I</a>/ <a href="http://www.codeproject.com/useritems/cppfaq25apr8jun.asp" target=_blank>IV</a>
|
|
|
|
|
Have I gone mad or has the 'this' window been removed from the debug windows you can see in VS.NET2005? Anyone noticed this? Or have a just missed where it now hidden away now.
|
|
|
|
|
Firstly I'd like to warn you all that this is a "Linux C" question and not anyway CLI related.
I've been doing some work on the PicoTux 100 module for a work project.
The background is that I've been porting an I2C driver for a Mitsubishi EEPROM to the PicoTux. The original file was a bit of a mess and everything was in one source file.
I've been moving various routines into seperate source files to tidy things up, between each move I build the entire project. Once I'd completed moving all routines to their various files I get messages similar to the ones below:
Error: symbol _Z10gpio_writeP13gpio_handle_tjj is undefined
Error: symbol _Z10gpio_writeP13gpio_handle_tjj is undefined
Error: symbol _Z16gpio_set_dir_outP13gpio_handle_tj is undefined
Error: symbol _Z10gpio_writeP13gpio_handle_tjj is undefined
Error: symbol _Z10gpio_writeP13gpio_handle_tjj is undefined
Error: symbol _Z10gpio_writeP13gpio_handle_tjj is undefined
The source compiles ok, this is in the linking stage.
There are routines called gpio_write in the source (well actually they're pre-compiled and I'm linking them in).
Does anyone have any ideas on how to track down where these bugs are?
This compilation is being done on Fedora Core 4 using the gcc compiler provided by PicoTux. I've setup MinGW Dev Studio to use the picotux compilers and created a project with two headers files (one has GPIO (General Purpose IO) definitions and the other has function prototypes & a few other I2C definitions). There are then several source files for the various functions.
Thanks in advance for any help
Ed
-- modified at 17:21 Wednesday 15th February, 2006
Ed
|
|
|
|
|
Do a search for Z10gpio_writeP13gpio_handle_tjj and find where it is in the code. Make sure that the file of library it's defined in is included in your project.
Steve
|
|
|
|
|
Z10gpio_writeP13gpio_handle_tjj is, I think, a decorated function name because:
1) There is no function (or anything infact) named Z10gpio_writeP13gpio_handle_tjj
2) This fails at the linking stage so "it has to be defined" because the source code compiles cleanly.
I've tried just now putting all the code into one source file and jiggling the headers to match. This compiles without any errors at all so I'll work like this to get the project done. In fact it can remain like this to simplify matters at the other end but it'd be nice to know why it failed.
Ed
|
|
|
|
|
If you declare a function without defining it things compile ok but you get a failure at link time. e.g.
void Foo();
int main(int argc, char* argv[])
{
Foo();
return 0;
}
To stop the link error you need to add the definition somewhere in your project. i.e.
void Foo()
{
}
You might be right about the name being mangled, you need the unmangled name, MSVC's linker gives both. If you can't find it you may need to guess. i.e, try "writeP13".
Steve
|
|
|
|
|
So, what do we know...
1) it doesn't work when items are in separate files. It complains about 'Z10gpio_writeP13gpio_handle_tjj' (which we think is a decorated name) not being defined at link time. As for my guess, the true routine name is gpio_write() and it's first argument is a gpio_handle object. Am I close?
2) it does work when we cram everybody into the same file - inelegant but all the names are there.
Hmm....
Question: in case (1) is the project building a mix of .c and .cpp files? If so, then I would say that the 'missing routines' live in a .c file and export undecorated names in the .o modules whereas the .cpp files are generating decorated names for the linker to fixup.
If that is the case then you need to ensure the .cpp code knows that the gpio_* routines are 'C' routines and not 'C++' routines. Checkout Linkage to Non-C++ Functions[^] for information on how to tell C++ code to expect undecorated names. Gcc surely provides a similar mechanism, if not this exact same one.
If that's not the case, then I guess an "oh well, never mind" is in order.
Later,
Dan
Remember kids, we're trained professionals. Don't try this at home!
-- modified at 18:59 Wednesday 15th February, 2006
|
|
|
|
|
Dan McCormick wrote: As for my guess, the true routine name is gpio_write() and it's first argument is a gpio_handle object. Am I close?
Close It's a gpio_handle_t . The integers in the name give the number of characters in the next section - it's a simple matter of counting I believe the 'j' means the parameter is a char , but I'm not sure.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
1) Here are the related GPIO routines (so your close :
gpio_status_t gpio_alloc(gpio_handle_t *, gpio_ports_t);
void gpio_close(gpio_handle_t *);
gpio_status_t gpio_free(gpio_handle_t *, gpio_ports_t);
gpio_dir_t gpio_get_dir(gpio_handle_t *, gpio_ports_t);
gpio_handle_t *gpio_open(void);
gpio_status_t gpio_read(gpio_handle_t *, gpio_ports_t, gpio_data_t *);
gpio_status_t gpio_set_dir_in(gpio_handle_t *, gpio_ports_t);
gpio_status_t gpio_set_dir_out(gpio_handle_t *, gpio_ports_t);
gpio_status_t gpio_write(gpio_handle_t *, gpio_ports_t, gpio_data_t);
Dan McCormick wrote: Question: in case (1) is the project building a mix of .c and .cpp files?
No C++, just pure ANSI C, I'm not compiling anything to do with C++.
As I said before, for this project I'll just continue with one source file as it's fairly small, < 500 lines of code. But it's more an annoyance than anything else.
Many Thanks Ed
|
|
|
|