Hi again! is there any way a program can read a .txt file without typing the .txt extension name? I need this for my ATM program for accessing an account number, it wouldn't look right if i have type 1234667.txt. I'm using Borland C++. Hope you can help me! Thanks!
#include <iostream.h>
#include <iomanip.h>
#include <fstream.h>
#include <cstring.h>
#include <string.h>
#include <conio.h>
//using namespace std;
int main() {
char account[80];
//char string1[] = "jay";
char string2[] = ".txt";
char string3[17];
cout <<"Enter Account No.:";
cin >> account;
strcpy(string3, account);
strcat(string3, string2);
int bal = 0;
int x;
ifstream inFile;
inFile.open(account);
if (!inFile) {
cout << "Unable to open file";
exit(1); // terminate with error
}
while (inFile >> x) {
sum = sum + x;
}
inFile.close();
cout << bal << endl;
getch ();
return 0;
}