Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting the ascii code for a string of text?

Status
Not open for further replies.

SmileeTiger

Programmer
Mar 13, 2000
200
0
0
US
What is the method for getting a string of text and then getting the ascii code for that string?<br><br>ie.<br><br>char test;<br>cin &gt;&gt; test<br>*something*<br>cout &lt;&lt; &quot;The ascii code is:&quot; &lt;&lt; test
 
Example:<br><br>String str;<br>char text[nn];<br><br>str=&quot;Any String&quot;;<br>strcpy(text,str.c_str());<br> <p>hnd<br><a href=mailto:hasso55@yahoo.com>hasso55@yahoo.com</a><br><a href= > </a><br>
 
A simple method is assign a char to a int :<br><br>char test;<br>int AsciiOfTest;<br><br>cin &gt;&gt; test<br>AsciiOfTest=(int)test;&nbsp;&nbsp;/* (int) to avoid a warning */<br>cout &lt;&lt; &quot;The ascii code is:&quot; &lt;&lt; AsciiOfTest; <p>Ferran Casarramona<br><a href=mailto: > </a><br><a href= > </a><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top