My output looks like this "T h i s m y o u t p u t" and I want it to look like this "This is my output". Any suggestions? I guess what Im asking is how do you take words from a file and put it into an array?
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
char fileName[80];
char a[30];
int names = 0;
ifstream myfile;
cout << "Enter file name: ";// Get filename from user
cin >> fileName;
myfile.open(fileName);
while(myfile.good() == false)// Prompt for new file name if not able to open
{
cout << "Unable to open file. Enter a different name: ";
cin >> fileName;
myfile.open(fileName);
}
while (myfile>>a[names])
{
cout<<a[names]<<" ";
}
myfile.close();
return 0;
}