473,624 Members | 2,656 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Converting from char[] to tstring

1 New Member
I have an application where I am querying a modem over a tcp socket. I can receive the data from the modem as expected into my char[1024] buffer but am having trouble then converting it to a tstring.

I am seeing some extra characters returning now (after a firmware upgrade) that I suspect are multi-byte characters which then screwup my checking routines.

Here is what I am doing currently

retString = (std::tstring)( (CString) recvBuf);

is there a better way to ensure if multi-byte characters are in the buffer they are handled correctly?
Jan 21 '10 #1
2 6344
johny10151981
1,059 Top Contributor
Hi,
I am not sure whether I have understood you.

But about multibyte data how do you know that they are multibyte. another thing is whether they are multibyte or not you will get them as single byte(8 bit). The reason is you have defined buffer as char (signed byte). if you have "私" char. Shift-JIS will return 2 bytes for it and char buffer will store this two bytes as two different bytes. not only this I know these bytes will be meaningful if i use Shift-JIS encoding only not any other encoding.

Let us know if you know anything about these or if I am wrong.

Best regards,
Johny
Jan 22 '10 #2
weaknessforcats
9,208 Recognized Expert Moderator Expert
Expand|Select|Wrap|Line Numbers
  1. retString = (std::tstring)((CString) recvBuf);
Tell me again how this cast converts a recvBuf (whatever type that is) to a CString that is then converted to a tstring?

Also, tell me how tstring is part of the std namespace.

If you can do that, your question will be answered.
Jan 22 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
5382
by: Prabhu | last post by:
Hi, We are having problem in converting a byte array to string, The byte array has char(174), char(175), char(240), char(242) and char(247) as delimiters for the message. when we use "System.Text.Encoding.ASCII.GetString(bytearray)" of .Net library, we found that the char (delimiters) specified above are replaced with different char.
4
3751
by: goldfita | last post by:
My last post - http://groups.google.com/group/comp.lang.c/browse_thread/thread/eacc2938b4c8ee66/0bdf6ab20a6007d0 I have a little bit more challenging question this time. Suppose I have write_cmd(struct ast_connection *conn, char *msg, ...); I want to call it like (forgive the syntax)
9
30503
by: Gregory.A.Book | last post by:
I am interested in converting sets of 4 bytes to floats in C++. I have a library that reads image data and returns the data as an array of unsigned chars. The image data is stored as 4-byte floats. How can I convert the sets of 4 bytes to floats? Thanks, Greg Book
0
2021
by: anide | last post by:
Hi all I’ve some problem, I’m trying to converting a sorting algorithm from C++ to C#. In C++ I’ve compiled it using MSVC and its working properly, and in C# I’m using .NET Framework 2.0 (Visual Studio 2005). The problem occurred when I trying to opening and reading file: ============= C++ ============= void LoadSourceFile(char * fileName, unsigned char * data, int length)
15
9650
by: allthecoolkidshaveone | last post by:
I want to convert a string representation of a number ("1234") to an int, with overflow and underflow checking. Essentially, I'm looking for a strtol() that converts int instead of long. The problem with strtol() is that a number that fits into a long might be too big for an int. sscanf() doesn't seem to do the over/underflow checking. atoi(), of course, doesn't do any checking. I've long thought it odd that there aren't strtoi() and...
2
1792
by: zmy12007 | last post by:
what different bettwen const tstring& str and tstring str as paramenter
1
3807
by: vcbytes | last post by:
I am having a problem with the following code: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { String^ texts = textBox1->Text; char *text = strToChars(texts); String^ shiftcs = domainUpDown1->Text; char *shiftc = strToChars(shiftcs); int shift = atoi(shiftc); char *cipher = encCCipher(text, shift); String^ ciphers = gcnew String(cipher); textBox2->Text = ciphers;
12
6606
by: kevin.eugene08 | last post by:
Hello all, Forgive the somewhat simple question I am sure this will be, but I am having some problem understanding what: char **argv looks like. For instance, i know through trial and error that if I do this: #include <stdio.h> int main(int argc, char *argv) {
12
5983
by: Jrdman | last post by:
hi, in some function prototypes why they use const char* instead of const char what's the need for const here is? if we must use const and why they don't use char *const instead because it's the right way to designate a const string (i think)?
4
3597
by: screamer81 | last post by:
Hello, I've a SDK functions description for a scanner and I try to convert unmanaged DLL C++ functions to c#. I converted all except one of them. This function is getting a struct parameter. int WINAPI ImgSave(_T_Scan_Param *ScanP, unsigned char *szMicr, int *num_chars, int y0, int y1, int cOcrCode_option) struct _T_Scan_Param { char file1;
0
8246
marktang
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...
0
8179
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
8685
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
7174
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
6112
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
4084
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4184
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1796
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1489
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.