#include <iostream>
#include <cmath>
#include <string>
#include <fstream>
usingnamespace std;
int main()
{
constint size = 30; // values for x,t
constint Size = 100; // for the characters
double t[size]; //array for t
double x[size]; //arrays for x
string a[Size];
int Count = 0;
string FName; // variable file name for data file
/////////
cout << "Please enter the name of the data file (Example: Data.dat): ";
cin >> FName;
ifstream InData;
InData.open(FName.c_str()); //Open file and convert name to C-style string
while(InData.fail())
{
cout << "Can't open file. Bad file name? Please re-enter file name: ";
cin >> FName;
InData.clear(); // clear fail bit
InData.open(FName.c_str()); //Open file and convert name to C-style str
}
cout << "File opened successfully!" << endl;
do
{ getline (InData, a[Count]);
Count++;}
while (!InData.eof() && Count < Size);
Count --;
for (int j = 0; j < Count; j++)
cout << a[j] << endl;
system("Pause");
return 0;
}
I am still a beginner in C++.
My objective is I want to be able to store the numbers only in the data file to an array, so I can be able to use them in functions. I figured how to save them into an array but I know its just using the array for my set up for the top 3 lines.I guess it saved everything as a string.