I need to find some sort of method to convert a series of char variables to a string, to be shown in a label. I've searched for two days and experimented myself just as long, and the closest I've gotten simply puts ASCII values into the string with the following command: - label1 -> Text = System::Convert::ToString(fdp8), System::Convert::ToString(fdp7), System::Convert::ToString(fdp6), System::Convert::ToString(fdp5), System::Convert::ToString(fdp4), System::Convert::ToString(fdp3), System::Convert::ToString(fdp2), System::Convert::ToString(fdp1);
fdp1-fdp8 are all char variables.
Thanks
12 4887
Use a stringstream; - string str;
-
char var = 123;
-
stringstream ss;
-
-
ss << var;
-
ss >> str;
You should see a { which is the ASCII symbol for 123.
If you actually need 123 in the string as three characters, then assign var to a temporary int variable: - string str;
-
char var = 123;
-
stringstream ss;
-
int temp = var;
-
ss << temp;
-
ss >> str;
And I now notice that your string is String, which is C# and not C++. I may have given an answer in the wrong language.
So is it C# or not?
It's C++, though I don't have the code available to test it. Also, what would the syntax be to put multiple char variables into the string/stringstream together in one command? Also, I'm fairly new to programming overall, and I'm not entirely sure what you meant about string being String. Thanks for the reply
The names of things in C++ are case-sensitive. So "string" is different from "String". "string" is part of the C++ standard library whereas "String" is not C++ at all but is part of the C# library. They work completely different.
Also "System" , as seen in your errors, is C# and not C++.
If you are asserting you are using C++, then do you mean "managed C++" that's promoted by Microsoft? This would be using Microsoft Visual Studio and creating C++ projects that have CLR support. The CLR is C#. These projects use both C++ and C# at the same time.
Banfa 9,065
Expert Mod 8TB
Strictly String is part of the .NET library not the C# library it is just that C# uses .NET.
Other languages that can use .NET are VB, J# C++ (and a whole host of other ones I can't remember/be bothered to name).
So yes String might normally be associated with C# but it is actually .NET which means you could be using it from a C++/CLR program.
It is however hard to mix CLI objects (like String) with native objects (like stringstream).
Yes it's with visual C++, so the combination of the two I guess
Well, now I am re-reading your original post where you say all that happens is the ASCII values of your Char variables are all that is in the String.
The ASCII values are all that is supposed to be in the String. What else were you anticipating?
Instead of showing actual characters in the label, it just shows the ASCII value of the first character.
Like this: - String str = "label = ";
-
char a = 'A';
-
char b = 'B';
-
str += a;
-
str += b;
-
Console.WriteLine(str);
?
I didn't see anything in your code snippet about appending the char variales together.
I heard of a string function "atoi" I think. Also, "itoa".
atoi and itoa are archaic C functions. This thread is Managed C++.
Banfa 9,065
Expert Mod 8TB
Actually itoa isn't even a C standard library function. It is an extension in some platforms is all.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Marcio Kleemann |
last post by:
I need to force the first letter of each word in a line of text to
uppercase. The text comes from a TextBox control in a Web Form. I'm new to
..NET and am having a problem.
Since I can't modify...
|
by: MilanB |
last post by:
Hello
How to convert char to int?
Thanks
|
by: claire |
last post by:
I have a char that i convert to a string as follows
m_tHeader.m_sshortname is defined as char;
string result = new string(m_tHeader.m_sshortname);
The problem is that any '\0' chars in the...
|
by: sposes |
last post by:
Im very much a newbie but perhaps somehone can help me. Ive been
searching for a way to convert a std::string to a unsigned char*
The situation is I have a function that wants a unsigned char*...
|
by: Joah Senegal |
last post by:
Hello I need to convert a chat to a string... but I don't know how to do
this. i;ve searched the internet but I've only find some code to convert
char * to string or char to string....
but I...
|
by: Kevin Frey |
last post by:
I am porting Managed C++ code from VS2003 to VS2005. Therefore adopting the
new C++/CLI syntax rather than /clr:oldSyntax.
Much of our managed code is concerned with interfacing to native C++...
|
by: Zytan |
last post by:
I am surprised that a single character string is not auto-created from
a single char. It is hard to find information on converting a char
into a string, since most people ask how to convert char...
|
by: ACSS |
last post by:
can anyone help me how can i convert char to String^
thanks...
|
by: mamul |
last post by:
Hi please some one can help me. how to convert char * to string?
i have take char *argv from command line and want to pass to a function as string object(string str)
i want to first convert argv...
|
by: DaveRook |
last post by:
Hi
I've had a few error messages with this I don't understand why. It works fine in a Windows Form, but now moving it to a website, it's not working. I don't have the option to count the lines as...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
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...
|
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,...
|
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...
|
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...
|
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...
| |