#include <iostream>
#include <string>
#include <fstream>
int main()
{
usingnamespace std;
ifstream file("data.txt");
if(file.is_open())
{
string myArray[5]; // or whatever size you need
for(int i = 0; i < 5; i++) // change 5 to the same size as above
{
file >> myArray[i]; // strings are stored in the array at position[i]
}
}
return(0);
}
Sorry, but I do not know what templates are or why you are using them for this assignment (I know you do not need a template, but I understand the teacher may be requiring it). Good luck.
I changed "Data" to "sand", but it is working properly now...what you wanted to do was not return a value...but make it a void...then, since you are "cout"ing something inside the function, just call the function in main and it will output the result...
If MyNewDataType is a string then the function will throw a logic error, you can't intialize a string from an integral literal.
1 2 3
/// might be it can be safer if you intialize your temp to the value of the first index.
MyNewDataType temp=arr [0]; //then iterate from the second index.