Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Convert to Static Char

Reply
Thread Tools

Convert to Static Char

 
 
IamZadok@hotmail.com
Guest
Posts: n/a
 
      02-28-2005
Hi

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



Thx

 
Reply With Quote
 
 
 
 
Rolf Magnus
Guest
Posts: n/a
 
      02-28-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) 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"?

 
Reply With Quote
 
 
 
 
Thomas Matthews
Guest
Posts: n/a
 
      02-28-2005
(E-Mail Removed) 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

 
Reply With Quote
 
Howard
Guest
Posts: n/a
 
      02-28-2005

"Thomas Matthews" <(E-Mail Removed)> wrote in
message news:(E-Mail Removed)...
> (E-Mail Removed) 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





 
Reply With Quote
 
Ioannis Vranos
Guest
Posts: n/a
 
      03-01-2005
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
 
Reply With Quote
 
Howard
Guest
Posts: n/a
 
      03-01-2005

"Ioannis Vranos" <(E-Mail Removed)> 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




 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
(const char *cp) and (char *p) are consistent type, (const char **cpp) and (char **pp) are not consistent lovecreatesbeauty C Programming 1 05-09-2006 08:01 AM
/usr/bin/ld: ../../dist/lib/libjsdombase_s.a(BlockGrouper.o)(.text+0x98): unresolvable relocation against symbol `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostre silverburgh.meryl@gmail.com C++ 3 03-09-2006 12:14 AM
char *fred; char * fred; char *fred; any difference? Ben Pfaff C Programming 5 01-17-2004 07:37 PM
The difference between char a[6] and char *p=new char[6] ? wwj C Programming 24 11-07-2003 05:27 PM
the difference between char a[6] and char *p=new char[6] . wwj C++ 7 11-05-2003 12:59 AM



Advertisments