C Board  

Go Back   C Board > General Programming Boards > C++ Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 05-09-2006, 04:37 PM   #1
Registered User
 
Join Date: May 2006
Posts: 18
Exclamation Help with storing letters in varibles

Hi again I also need help with storing letters in varibles thanks again
cgsarebeast is offline   Reply With Quote
Old 05-09-2006, 04:43 PM   #2
Registered User
 
Join Date: Feb 2006
Posts: 304
char is the data type for storing single characters...
Code:
char x = 'c'; 
//variable x holds the letter 'c'
Bench82 is offline   Reply With Quote
Old 05-09-2006, 04:49 PM   #3
Registered User
 
Join Date: May 2006
Posts: 18
thanks agian Bench82 how u hold multipule charaters
cgsarebeast is offline   Reply With Quote
Old 05-09-2006, 04:53 PM   #4
Registered User
 
Join Date: Feb 2006
Posts: 304
Quote:
Originally Posted by cgsarebeast
thanks agian Bench82 how u hold multipule charaters
characters stored contigiously (is that a word? - I mean "stored next to each other in memory" anyway) are generally known as strings... Since you're in the C++ forum, I'll assume you're not using C.. here is the C++ way to do it, using the C++ <string> library :
Code:
#include <iostream>
#include <string>
using namespace std;

int main()
{
   string s = "Hello, World";
   cout << s;
   cin.get();
}
There's a different way to do it in C, which involves character arrays - that works in C++ too.. but in C++, use the method above unless you have a compelling reason to do otherwise
Bench82 is offline   Reply With Quote
Old 05-09-2006, 05:08 PM   #5
Registered User
 
Join Date: May 2006
Posts: 18
o ic thanks but I'll give u an example:

Code:
 #include <iostream>

using namespace std;

int main ()

{	
	cout<<"Name 1.0 \n"; 
    cout<<"Please Press Enter \n";
	cin.get ();
	
    int x;

	cout<<"Please Input your name: ";
	cin>> x;
	cin.ignore ();
	cout<<"Is this your name?: "<< x <<"\n";
	cin.get ();

}
(I know thats the example of the "enter your number" thing on this site but with words changed, I'm useing it 2 learn....)

well ne ways I want that code 2 display a letter instead of a number and I dont know what varible 2 use or even if u use one

thanks.....
cgsarebeast is offline   Reply With Quote
Old 05-09-2006, 05:08 PM   #6
Registered User
 
Join Date: May 2006
Posts: 18
oh and yes I'm useing C++
cgsarebeast is offline   Reply With Quote
Old 05-09-2006, 05:26 PM   #7
Registered User
 
Join Date: Jan 2005
Posts: 7,137
Use the string variable that Bench82 showed you. He showed output, but it should be easy to change to input if you know how to input a number.
Daved is offline   Reply With Quote
Old 05-09-2006, 05:33 PM   #8
Registered User
 
Join Date: May 2006
Posts: 18
thanks, but with that how could the user change it like if I put a set value than if I put the value a sally than if there names not sally it would work?
cgsarebeast is offline   Reply With Quote
Old 05-09-2006, 05:49 PM   #9
Registered User
 
Join Date: Jan 2005
Posts: 7,137
Just replace int in your code with string (and add the #include <string>). They are both types that can be used in the same way in this case.

Then try it out and ask questions about the exact code if you get stuck.
Daved is offline   Reply With Quote
Old 05-09-2006, 06:03 PM   #10
Registered User
 
Join Date: May 2006
Posts: 18
YaY thanks Daved...
cgsarebeast is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Generating random letters ominub C Programming 6 04-29-2009 01:12 AM
need to count individual letters in input epox C Programming 12 05-22-2006 06:32 AM
Counting letters and digits FeNCinGeR C++ Programming 3 04-06-2006 11:39 AM
problems storing values in varibles stodd04 C Programming 7 02-08-2005 11:56 AM
Switching letters XiReDDeViLiX Windows Programming 4 06-06-2002 06:48 AM


All times are GMT -6. The time now is 10:00 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22