Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works
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