Variables

This is a discussion on Variables within the C++ Programming forums, part of the General Programming Boards category; Hi all, I'm trying to make a variable contain a whole word. So far I've got something that works, but ...

  1. #1
    Registered User
    Join Date
    Apr 2004
    Posts
    14

    Variables

    Hi all,

    I'm trying to make a variable contain a whole word. So far I've got something that works, but i'm not sure if this is the 'correct' way to do it. I'm just doing: char varname[0]. Doesn't seem right to me, could anyone be kind enough to give me a pointer?

    Thanks very much,
    Mike

  2. #2
    Registered User
    Join Date
    Dec 2003
    Posts
    28
    Maybe try string ?

  3. #3
    Magically delicious LuckY's Avatar
    Join Date
    Oct 2001
    Posts
    856
    A "variable containing a whole word?"

    Use a string object
    Code:
    #include <iostream>
    #include <string>
    
    int main() {
      std::string str = "blah blah blah...";
      std::cout << str.c_str() << std::endl;
      return 0;
    }
    or a C-style string
    Code:
    #include <cstring>
    #include <iostream>
    
    int main() {
      char str[30];
      strcpy(str, "here's some text");
      const char *pointer = "here's a constant string.";
      std::cout << str << std::endl << pointer << std::endl;
      return 0;
    }

  4. #4
    Registered User
    Join Date
    Apr 2004
    Posts
    14
    Thanks guys!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. basic question about global variables
    By radeberger in forum C++ Programming
    Replies: 0
    Last Post: 04-06-2009, 12:54 AM
  2. Replies: 15
    Last Post: 09-30-2008, 02:12 AM
  3. esbo's data sharing example
    By esbo in forum C Programming
    Replies: 49
    Last Post: 01-08-2008, 10:07 PM
  4. Replies: 6
    Last Post: 01-02-2004, 12:01 PM
  5. functions to return 2 variables?
    By tim in forum C Programming
    Replies: 5
    Last Post: 02-18-2002, 01:39 PM

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