472,145 Members | 1,499 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,145 software developers and data experts.

Convert to Static Char

Hi

I was wondering if anyone knew how to convert a string or an integer
into a Static Char.

Thx

Jul 23 '05 #1
5 6013
Ia******@hotmail.com wrote:
Hi

I was wondering if anyone knew how to convert a string or an integer
into a Static Char.


What exactly do you mean by "Static Char"?

Jul 23 '05 #2
Ia******@hotmail.com wrote:
Hi

I was wondering if anyone knew how to convert a string or an integer
into a Static Char.

Thx


Try this:
static char c;

int main(void)
{
c = 'A'; // Converts 'A' into a static char.
c = '1'; // Converts a literal numeric into a char.
return 0;
}

If this doesn't satisfy you, please be more descriptive
as to what you are seeking.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.comeaucomputing.com/learn/faq/
Other sites:
http://www.josuttis.com -- C++ STL Library book
http://www.sgi.com/tech/stl -- Standard Template Library

Jul 23 '05 #3

"Thomas Matthews" <Th*************************@sbcglobal.net> wrote in
message news:42************@sbcglobal.net...
Ia******@hotmail.com wrote:
Hi

I was wondering if anyone knew how to convert a string or an integer
into a Static Char.


Try this:
static char c;

int main(void)
{
c = 'A'; // Converts 'A' into a static char.
c = '1'; // Converts a literal numeric into a char.
return 0;
}

If this doesn't satisfy you, please be more descriptive
as to what you are seeking.

--
Thomas Matthews


Well, considering he asked about converting a string or an integer, and
since 'A' is not a string and '1' is not an integer, I suspect it won't
satisfy.

Like you, however, I await clarification as to exactly what the heck he
*does* want! :-)

To the OP:

When you say you want to "convert ... to a static char", that doesn't really
make sense. Do you mean you want to know how to put the contents of a
string (i.e., std::string) into an array of char (a C-style string), and how
to convert an integer into an C-style string as well? Or...???

A char (watch your capitalization, it's important in C++) is a single
character, and is not going to be able to hold an integer (if it's outside
the range of 0..9) or a string (if the string is longer than 1 character).

With the keyword "static" in front of it, it means different things,
depending upon where it's used. A static member variable is different from
a non-member variable declared as static. (I hate that those different
concepts use the same keyword, but what're you gonna do, eh? :-))

Research the keyword "static". Also research "array of char", or C-style
strings. And if by "string" you meant the class std::string, look that up,
too.

-Howard

Jul 23 '05 #4
Howard wrote:
A char (watch your capitalization, it's important in C++) is a single
character, and is not going to be able to hold an integer (if it's outside
the range of 0..9)

I am sure you did not mean what it sounds that you said, but we have to
be technically correct. :-)

A char can hold integer values from numeric_limits<char>::min() to
numeric_limits<char>::max() the latest being always at least 127.
The following code displays these ranges in a system:
#include <iostream>
#include <limits>

int main()
{
using namespace std;

cout<<static_cast<int>( numeric_limits<char>::min() )<<"\n"
<<static_cast<int>( numeric_limits<char>::max() )<<"\n";
}
In my system it outputs:

C:\c>temp
-128
127

C:\c>

--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 23 '05 #5

"Ioannis Vranos" <iv*@remove.this.grad.com> wrote in message
news:1109640191.100742@athnrd02...
Howard wrote:
A char (watch your capitalization, it's important in C++) is a single
character, and is not going to be able to hold an integer (if it's
outside the range of 0..9)

I am sure you did not mean what it sounds that you said, but we have to be
technically correct. :-)


Right, sorry. What I meant was that if you are using an array of char to
display an integer that has been "converted" to a string, such as with itoa,
sprintf, or a stringstream, then a single char in that array will only hold
one decimal digit of that integer. So the number 127 would need an array of
at least three chars, i.e., ['1','2','7'] (plus one more for the
null-terminator if used as a C-style string). And since the OP asked about
converting an integer to a {static} char, I wanted to point out that he
probably meant an _array_ of char, not just a single char. Assuming, of
course, I understood what he meant by "convert"! :-)

Thanks,
Howard


Jul 23 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Abhishek Jha | last post: by
3 posts views Thread by GM | last post: by
40 posts views Thread by Tameem | last post: by
4 posts views Thread by Peter | last post: by
reply views Thread by leo001 | last post: by

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.