c++ data types - Geeks to Go Forums

Jump to content

Log in Register Register Malware removal guide How it works

c++ data types for words?

#1 akashlee

  • Group: Member
  • Posts: 126
  • Joined: 22-July 05

  Posted 02 August 2005 - 11:03 AM

hi again
i was just wondering how come there is no variable type (like int) that suppors words? ;)
i am tyring to make a program that simply just responds to a user, but all my program is accepting is numbers.
what do i do?
yes i already tried google. :tazz:

#2 akashlee

  • Group: Member
  • Posts: 126
  • Joined: 22-July 05

Posted 02 August 2005 - 01:48 PM

Anyone?

#3 NullWolf

  • Group: Member
  • Posts: 225
  • Joined: 13-July 05

Posted 02 August 2005 - 02:57 PM

It's been a few years since I did C++, so someone can feel free to correct any mistakes / wrongness in my answer. (BTW, u just posted it this morning, chill and people will answer.)

There aren't variables for strings / characters.
To make a "variable string" you'd have to first create a constant for the string.
Lets say for example, you set 3 "random" responses to whatever the user types.

You'd set 3 constants, then randomly call the constants.
Gimme a day and I'll find a good example. Needed to get back into programming anyways. ;)

I'm sure some kind soul will have answered this by then, but I'll find it anyway. :tazz:

In the meantime, you may want to check this:
http://www.free2code.../read.php?id=90

#4 inoxx.net

  • Group: Member
  • Posts: 16
  • Joined: 29-July 05

Posted 02 August 2005 - 03:51 PM

yeah there is, a string:
#include <string>
#include <iostream>
using namespace std;

int main()
{
string bob = "Hello, im a string\n";
cout << bob;
return 0;
}


or you could use a char array
#include <iostream.h>

int main()
{
char *mychar;     // this is a pointer
mychar = "Hello";

cout << "mychar has the value of: " << mychar << "\n" << "and the address in memory of: " << &mychar << "\n";

return 0;
}


Share this topic: