Randomly pick a first name from a file I have a very easy question for you guys out there. It's been a while since I took my programming courses (switched majors) but am trying to get my feet wet again.
Objective:
I will be creating a program that will output 10 random full names (and have it be different every time the program is run).  Before I complete it, I'd like some feedback on the first iteration, which just chooses random first names.
Info:
I have a file called firstnames.txt, containing a list of 10 first names.
Premise:
I'm a beginner and I/O really throws me.  I feel this is a basic enough program for me to learn from, and with your advice, I'll be able to copy/paste the same code to get a last name.
Thanks!
Here's what I have so far:
#include &lt;windows.h&gt;
#include &lt;cstdlib&gt;
#include &lt;iostream&gt; 
#include &lt;string&gt; //random headers because it's been awhile :P
#include &lt;fstream&gt;
#include &lt;time.h&gt;

using namespace std;

int main()
{
//Variable declarations
int a = 0;
int randNum;

ifstream myFile;
myFile.open(&quot;firstnames.txt&quot;);
string names[10]; // holds the 10 names in the file.
string randomNames[10];// holds the randomly generated names FROM the file.

while (myFile.good())
{
    getline(myFile, names[a]); // reads the names from the text file, into an array named &quot;names[].&quot;
    a++;
}
for (int i = 0; i &lt; 10; i++)  // makes this program iterate 10 times; giving you 10 random names.
{
    srand( time(NULL) ); // seed for the random number generator.
    randNum = rand() % 10 + 1; // gets a random number between 1, and 10.
    randomNames[i] = names[randNum];
}
for (int i = 0; i &lt; 10; i++)
{
    cout &lt;&lt; randomNames[i] &lt;&lt; endl; // outputs all 10 names at once.
}

myFile.close();
return EXIT_SUCCESS;
}

My firstnames.txt looks like:
Ryan
John
Daniel
Gavin
Frank
Danielle
Lucy
Sarah
Katie
Nicole

My lastnames.txt will look similar:
Johnson
Lewis
Walker
Robinson
Wood
Thompson
White    
Watson
Jackson
Wright

(Another question I guess would be is the way I formatted the names (each name on a new line) a bit over complicated in the text file? Like would it be better/shorter to just separate each name by a space or something?)
Thanks again!
Well, at least you know what's wrong here:

#include &lt;string&gt; //random headers because it's been awhile :P


You actually need: &lt;iostream&gt;, &lt;string&gt;, &lt;ctime&gt; and &lt;cstdlib&gt;.
You are using using namespace std;.
That's a bad idea, read "Why is “using namespace std;” considered bad practice?".
It's safer and more flexible to use a std::vector, though admittedly insignificantly less efficient.

std::vector&lt;std::string&gt; names;

There's no good reason why you first generate all the data and safe it in memory just to dump it all afterwards in one go.
There's a reason while(!found_end) {read_some_more; process_it;} doesn't work:
You only know you have reached the end after you tried to read beyond it.

for (std::string line; std::getline(myFile, line) &amp;&amp; !line.empty(); )
    names.push_back(std::move(line));

If you extract the code to read names from a file into a function your code does not only get cleaner, you can also reuse it.
You are re-seeding the old toy-RNG repeatedly in a relatively tight loop. Can you see where that might not be all that great for randomness?

Anyway, C++11 provides far better RNGs in &lt;random&gt;. See "Seed std::mt19937 from std::random_device" for how to properly seed one.
Ending main with return EXIT_SUCCESS; is equivalent to ending it with return 0; which can be omitted (but only for main).


Following my suggestions lets you loose &lt;ctime&gt; and &lt;cstdlib&gt; but adds &lt;vector&gt;, &lt;utility&gt;, &lt;functional&gt;, &lt;random&gt; and &lt;algorithm&gt;.

#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;vector&gt;
#include &lt;utility&gt;
#include &lt;functional&gt;
#include &lt;random&gt;
#include &lt;algorithm&gt;

static std::vector&lt;std::string&gt; read_names(const std::string&amp; filename)
{
    std::vector&lt;std::string&gt; names;
    std::ifstream file(filename);
    for(std::string name; std::getline(file, name) &amp;&amp; !name.empty(); )
        names.push_back(std::move(name));
    return names;
}

static const std::string&amp; choose_any(
    std::mt19937&amp; rng,
    const std::vector&lt;std::string&gt;&amp; names
) {
    return names[std::uniform_int_distribution&lt;size_t&gt;(0, names.size() - 1)(rng)];
}

static std::mt19937 ProperlySeededRandomEngine()
{
    std::mt19937::result_type random_data[std::mt19937::state_size];
    std::random_device source;
    std::generate(std::begin(random_data), std::end(random_data), std::ref(source));
    std::seed_seq seeds(std::begin(random_data), std::end(random_data));
    std::mt19937 seededEngine (seeds);
    return seededEngine;
}

int main()
{
    auto firstnames = read_names("firstnames.txt");
    auto lastnames = read_names("lastnames.txt");
    auto rng = ProperlySeededRandomEngine();
    for(int i = 0; i &lt; 10; ++i)
        std::cout &lt;&lt; choose_any(rng, firstnames) &lt;&lt; ' '
            &lt;&lt; choose_any(rng, lastnames) &lt;&lt; std::endl;
}