use words in variables?

Hello, I just started programming a few days ago, and I am desperately looking for an answer to my prayers! :P

How do I use words in variables?
I can only do int blabla = random number.. But I don't want that, I want my program to be able to use letters in input, for example:

int main()
{
variable word; // whatever the command is named

cin >> word;
cout << "you typed this word: " << word;
}

Maybe I am speaking russian to you, but if you can understand my question, I would be very happy if you could answer it too :)
you were missing substantial code in your function, take a look at the revised code with comments included, good luck!

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

#include <iostream>// the header iostream, which supports the C++ I/O system
#include <cstdlib> //c++ standard library header
using namespace std; //this tells the compiler which namespace to use


int main()//calls the function 'main()', execution begins here
{ // formally starts execution
     char word[80];//this statement identifies 'word' as a character string


     cout << "Type in a word\n";// '\n' console output/creates a new line

     cin >> word;//console input /input character string
     cout << "you typed this word:\n" << word; // output character string entered

     return 0; //  This line terminates main( ) and causes it to return the value 0 to the calling    process 
}// formal end of function 





Type in a word
Serendipity
you typed this word:
Serendipity

Last edited on
std::strings are much better than char arrays
well from some of the input ive been getting back Bazzy, the herbert shildt guide for beginners isnt the best one to sink your teeth into if your a beginner, however, I am on chapter 7 of 12, so i will finish it then get a different one learn from, so in essence i will be taking two beginner courses due to perceived neccesity on my part, i actually found a mistake when transcribing notes yesterday in chapter 2 where he went into great detail stating that integers were by default signed integers and thats why they could hold a negative value,, well, i wasted 20 minutes scratching my head and rereading until i changed my notes on my own to unsigned, then moved on to the next page where he was correct in further references to signed. that WAS confusing
What is this comment in response to? Did someone recommend the herbert shildt guide for beginners (which I've never heard of)?

you were missing substantial code in your function


2 or 3 lines? And you don't need #include <cstdlib>

Stick with strings where ever possible.
Last edited on
Herbert Schildt's C++ Beginner's Guide is the one I am using, i mentioned it in the forum and got some feedback that it isnt all that encompassing, he was on the ansi/iso committee that standardized c++, I think it is a good beginners guide, but the syntax is much different than what I regularly see here, so I will need to compliment it with another beginners book, any suggestions?
You hijacked the thread with your comment. Take a look at C++ How to Program (6th Edition) also 7th edition was just released. It is alll encompassing including Boost, Ogre3d, UML, etc...
Thank you very much Return! I will look into that guide asap :)
Topic archived. No new replies allowed.