Hello
I am writing a function to read a binary file. Here is a part of code
#include <fstream>
..
..
BYTE *pData;
long lDataLen;
pms->GetPointer(&pD ata);
lDataLen = pms->GetSize();
// Read one line at a time till end of file..
if (m_inFile.getli ne(pData,
lDataLen))pms->SetActualDataL ength(strlen((c har*)pData)+1);
else {return S_FALSE;}
............... ....
The error message that i get is this
error C2664: 'class std::basic_istr eam<char,struct
std::char_trait s<char> > &__thiscall std::basic_istr eam<char,struct
std::char_trait s<char> >::getline(ch ar *,int)'
: cannot convert parameter 1 from 'unsigned char *' to 'char *'
Types pointed to are unrelated; conversion requires
reinterpret_cas t, C-style cast or function-style cast
Conflict in datatypes is causing this error. How can i solve this
problem? Which type of casting is better here and how it should be
used here.
thanks 2 6043
"seia0106" <mi*******@yaho o.com> wrote in message
news:4f******** *************** ***@posting.goo gle.com... Hello I am writing a function to read a binary file. Here is a part of code #include <fstream> . . BYTE *pData; long lDataLen; pms->GetPointer(&pD ata); lDataLen = pms->GetSize(); // Read one line at a time till end of file.. if (m_inFile.getli ne(pData, lDataLen))pms->SetActualDataL ength(strlen((c har*)pData)+1); else {return S_FALSE;} ............... ... The error message that i get is this
error C2664: 'class std::basic_istr eam<char,struct std::char_trait s<char> > &__thiscall std::basic_istr eam<char,struct std::char_trait s<char> >::getline(ch ar *,int)' : cannot convert parameter 1 from 'unsigned char *' to 'char *' Types pointed to are unrelated; conversion requires reinterpret_cas t, C-style cast or function-style cast
Conflict in datatypes is causing this error. How can i solve this problem? Which type of casting is better here and how it should be used here. thanks
Why are you trying getline in a binary file? getline is for text files.
Anyway you can cast pData to the required type, one of the few common
instances where a cast is justified.
if (m_inFile.getli ne((char*)pData ,lDataLen))
But the fact that you cast pData to (char*) twice, suggests that maybe you
would do better to declare is as char* in the first place. After all it does
appear to be text data, and char* is used for text.
john
Thank you for the reply.
The file is a text file. I have tried to do it the way you said but it
is still not working. In this function *pData must be declared as a
'BYTE'type. So how to use a 'BYTE' type *pData as a first parameter of
getline() method and in strlen()? The error is same that
"cannot convert parameter 1 from 'const char ** ' to 'unsigned char **
'"
I have looked into the text books for unsigned char type, char type
and signed char type but I am little confused about their differences
and uses.
thanks in advance
"John Harrison" <jo************ *@hotmail.com> wrote in message news:<bg******* *****@ID-196037.news.uni-berlin.de>... "seia0106" <mi*******@yaho o.com> wrote in message news:4f******** *************** ***@posting.goo gle.com... Hello I am writing a function to read a binary file. Here is a part of code #include <fstream> . . BYTE *pData; long lDataLen; pms->GetPointer(&pD ata); lDataLen = pms->GetSize(); // Read one line at a time till end of file.. if (m_inFile.getli ne(pData, lDataLen))pms->SetActualDataL ength(strlen((c har*)pData)+1); else {return S_FALSE;} ............... ... The error message that i get is this
error C2664: 'class std::basic_istr eam<char,struct std::char_trait s<char> > &__thiscall std::basic_istr eam<char,struct std::char_trait s<char> >::getline(ch ar *,int)' : cannot convert parameter 1 from 'unsigned char *' to 'char *' Types pointed to are unrelated; conversion requires reinterpret_cas t, C-style cast or function-style cast
Conflict in datatypes is causing this error. How can i solve this problem? Which type of casting is better here and how it should be used here. thanks
Why are you trying getline in a binary file? getline is for text files.
Anyway you can cast pData to the required type, one of the few common instances where a cast is justified.
if (m_inFile.getli ne((char*)pData ,lDataLen))
But the fact that you cast pData to (char*) twice, suggests that maybe you would do better to declare is as char* in the first place. After all it does appear to be text data, and char* is used for text.
john This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Vijay Kumar R Zanvar |
last post by:
Hi,
Which section of C99 says that return value
of malloc(3) should not be casted?
Thanks.
--
Vijay Kumar R Zanvar
My Home Page - http://www.geocities.com/vijoeyz/
|
by: Method Man |
last post by:
Say I have the following:
int main(void) {
char* p, q;
p = (char*) malloc(sizeof(char)*10);
q = (p + 100) - 99; /* legal? */
free(q - 1); /* legal? */
....
return 0;
}
|
by: rahul8143 |
last post by:
hello,
In kernel source code there is ip_fragment.c file my question is
regarding pointer function and casting for that look at required
snippet from that file
There is structure defined for queueing ip fragments as
struct ipq {
struct ipq *next; /* linked list pointers */
struct list_head lru_list; /* lru list member */
u32 user;
u32 saddr;
|
by: SStory |
last post by:
3rd time trying to post this but never see it in the list:
===================================
In VB.NET, am doing the following with my MDI app..
Please advise if I am going about this wrong or there is a better way.
I thought, well, the main form needs to be able to ask the child form if it
can save
|
by: René Nordby |
last post by:
Hi there,
Is there anyone that knows how to do the following?
I have a class A and a class B, that 100% inherits from class A (this means
that I don't have other code in class B, than the Inherit statement).
| |
by: Enekajmer |
last post by:
Hi,
1 int main()
2 {
3 float a = 17.5;
4 printf("%d\n", a);
5 printf("%d\n", *(int *)&a);
6 return 0;
7 }
|
by: Smithers |
last post by:
Are there any important differences between the following two ways to
convert to a type?... where 'important differences' means something more
profound than a simple syntax preference of the developer.
x = someObject as MySpecificType;
x = (MySpecificType) someObject;
Thanks.
|
by: tshad |
last post by:
Using VS 2003, I am trying to take a class that I created to create new
variable types to handle nulls and track changes to standard variable types.
This is for use with database variables. This tells me if a variable has
changed, give me the original and current value, and whether the current
value and original value is/was null or not.
This one works fine but is recreating the same methods over and over for
each variable type.
...
|
by: alex.j.k2 |
last post by:
Hello all,
I have "PRECISION" defined in the preprocessor code
and it could be int, float or double, but I do not know in the
code what it is.
Now if I want to assign zero to a "PRECISION" variable,
which of the following lines are correct:
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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,...
| |
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...
|
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,...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |