Thread: String Statement problem

  1. #1
    Registered User snowy101's Avatar
    Join Date
    May 2002
    Posts
    22

    String Statement problem

    ok i declared string word2; in c++ borland vrs 6 and i wanted to add records or varibles , whatever you call them so i wrote it like this string word2[10]; now it runs the program but what i want to be displayed does not display the amount of characters i am reading is no more then 5 so 10 should work fine. i need to know why its not displaying heres a peice of code that might help you solve my problem.

    #include <string.h>

    string word2[10];

    for(a = 1;a <= filecount; a = a + 1)//filecount counts how many
    times it loops in scan.
    {
    cout << word2[a] <<" ";
    }

    now this should display word2 but it doesn't plz help

  2. #2
    Unregistered
    Guest
    The code you have posted does not have anything in word2. And you do not need to loop to display the array:

    const int WORD_SIZE = 10;

    char word[WORD_SIZE];

    strcpy( word, "Hello" ); // Put something in the array

    cout << word << endl; // you can output it like a char pointer

  3. #3
    Registered User snowy101's Avatar
    Join Date
    May 2002
    Posts
    22

    Thanks

    Thanks for the help i thought i had to use a string to compare to the characters in the .txt file i was scanning thanks for the help!

  4. #4
    Registered User
    Join Date
    Jun 2002
    Posts
    4

    Question

    I have a quick little question. I notice that most of the time I see people asking about string.h, but why not just use APstring?(and the other APclasses for that matter ie..apvector, apmatrix) Is it just you reply using what the original post-er used. Or is it that you dont use it much. Im just curious to know how many actually use these...thanks

  5. #5
    Unregistered
    Guest
    I'm not sure what you're trying to do here.... string word2[10]; creates an array of 10 strings. You only need string word2; or char word2[10];.

  6. #6
    Unregistered
    Guest
    Also, if you wanted to use that loop to display it, a should start at 0 (array elements are numbered starting at 0)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Inheritance Hierarchy for a Package class
    By twickre in forum C++ Programming
    Replies: 7
    Last Post: 12-08-2007, 04:13 PM
  2. string problem
    By INeedSleep in forum C++ Programming
    Replies: 24
    Last Post: 11-08-2007, 11:52 PM
  3. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  4. Replies: 5
    Last Post: 11-07-2005, 11:34 PM