I'm trying to make the c++ program that read the alphabet from "abc.txt" and split by space, and then save in array (arrFirst).
My environment is Visual Studio 2019.
(I'm not good at English. I'm sorry if my writing is hard to read)
This is my code, and I have "abc.txt" in same directory with this .cpp file.
This code can't open the "abc.txt" file.
I can't understand why this code can't open the file.
Could you tell me why this code can't open the txt file??
Thank you.
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
char arrFirst[30];
int position = 0;
int arrFirstSize = sizeof(arrFirst) / sizeof(arrFirst[0]);
ifstream fin;
fin.open("abc.txt");
if (fin.is_open())
{
cout << "File Opened Successfully! " << endl;
while (!fin.eof() && position < arrFirstSize);
{
fin.get(arrFirst[position]);
position++;
}
arrFirst[position - 1] = '\0';
cout << "Displaying Array... " << endl << endl;
for (int i = 0; arrFirst[i] != '\0'; i++)
{
cout << arrFirst[i];
}
}
else
{
cout << "File could not be opened." << endl;
}
return 0;
}