Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

C++ Array...

C++ Array...

C++ Array...

I'm very new to C++.

I have the following string (called 'names'): "Cameron;Keremy;Jyle;Tyson;".

How do I turn this into an Array?
names[0] would be Cameron, names[1] would be Keremy, etc.?

I really would appreciate some help with this please!

RE: C++ Array...

Show some code and we can give a better answer than just guessing.

RE: C++ Array...



// main3b.cpp
// This holds a number game
// Copyright (c) 1998

#include <iostream.h> // For input/output
#include <fstream.h> // For file input/output
#include <string.h>  // For strcpy
#include <time.h>  // For time
#include <stdlib.h>  // For toupper and tolower

// The main function of our number game
int main(void)

    using namespace std;
    int PlayersAmount;
    string Player("");
cout<<"Welcome to MultiPlayer Strategy by Cameron McKinnon. Enjoy!\n\n\nOkay, time to start the game! First, you're going to have to answer some \nquestions.\n\n\n***\nHow many people will be playing?\n***\n\nNumber of players: ";
int count = 0;

                         string Player; //note: the [] appears after the variable

//populate array:

                           string Currentplayer("");

                           int saycount=count+1;
                           cout<<"Player "<<saycount<<", please enter your desired username: \n\n";

                           Player[saycount] = Currentplayer;
                           count ++;

    return EXIT_SUCCESS;

RE: C++ Array...

Try vector<string>
Then use the push_back() method of vector to add strings to it, size() to see how many strings are in it, and you can access each string just like an array (with the var[n] format).

RE: C++ Array...

okay thanks.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close