Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

c++ data types


  • Please log in to reply

#1
akashlee

akashlee

    Member

  • Member
  • PipPipPip
  • 126 posts
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:
  • 0

Advertisements


#2
akashlee

akashlee

    Member

  • Topic Starter
  • Member
  • PipPipPip
  • 126 posts
Anyone?
  • 0

#3
NullWolf

NullWolf

    Member

  • Member
  • PipPipPip
  • 225 posts
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

Edited by NullWolf, 02 August 2005 - 03:01 PM.

  • 0

#4
inoxx.net

inoxx.net

    Member

  • Member
  • PipPip
  • 16 posts
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;
}

Edited by inoxx.net, 02 August 2005 - 03:52 PM.

  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP