string n[5]={"jay", "mike", "paul", "billy", "adam"};
for (i=0; i<5; i++)
cout << n[i] << "\n"; // loops through the array's index and display each string
Although it's generally safer to put the braces around a block even when it's a single line:
1 2 3 4 5 6 7
string n[5]={"jay", "mike", "paul", "billy", "adam"};
for (i=0; i<5; i++)
{
cout << n[i] << "\n"; // loops through the array's index and display each string
}
If I had a quid for every bug I've seen introduced into code that would have been prevented by this, I wouldn't have to keep writing C++ for a living :)
string n[5]={"jay", "mike", "paul", "billy", "adam"};
for (int i=0; i<5; i++)
cout << n[i] << "\n"; // loops through the array's index and display each string
Let me tell you what is happening, there is data given like that
jay 44 55 66 77 88 33
mike 44 22 77 22 11 76
paul ...
billy
adam
and when I do the for loop we are all talking about, what I am getting is
jay 44 55 66 77 << the numbers are being placed in the string, i want to place the names only !
@MikeBoy
there is no compiler error i was just giving an example. but the the real thing is Data like that and i have to use ifstream, i do not want to get too much into it i just want to understand why it is not putting the names only
W have a data on text file that has something like that
jay 44 55 66 77 88 33 27
mike 44 22 77 22 11 76 78
paul ...
billy
adam
i need to take the names and store them into a string array
then take the numbers, and store them into a two dimensional integer array, i need to calculate the total numbers for each name at the end. but I am still stuck on getting the names inside the string from he first place.