infile string Array

I have to copy words in from a text file into a array i used a code that looks like this. My code errors I was hoping one of you could tell me what i am doing wrong.
up top i used this to declair my stuff
-------------------------------------------
string one,two,three,four,five;
string words[6];
-------------------------------------------

this part of my code i was trying to copy in the string

infile.open("words.txt");

infile >>one>>two>>three>>four>>five;

cout << "Reading 5 numbers from file: ";
strcpy(words[0],one);
strcpy(words[1],two);
strcpy(words[2],three);
strcpy(words[3],four);
strcpy(words[4],five);
http://www.cplusplus.com/reference/clibrary/cstring/strcpy.html
char * strcpy ( char * destination, const char * source );
I am not sure what that means can you explain ??
I have to read 5 words from a text file and place the words back into an array.
So i have a text file named words.txt with 5 words in the file
I have to take the words and place them in the words[] array in slots 0 to 4 and then print them on the screen. The page you linked doesn't help me and the code you placed doesn't help either.
That is the prototype for strcpy(). Notice that it takes two pointers to chars, but that you're passing it two std::strings.
std::strings have the assignment operator overloaded to make things easier.
Last edited on
Topic archived. No new replies allowed.