Buna benzer başka konular var, ancak hiçbiri tamamen aynı sorunla ve hiçbiri benim için çalışmıyor. İşte Ben ile çalışıyorum açılış kodu:ifstream dosyası açılamıyor
ifstream inputFile;
string filename;
cout << " Tablerock Member Services" << endl;
cout << "***************************\n\n" << endl;
cout << " Please enter the name of the member file: ";
cin >> filename;
inputFile.open(filename);
dosya MemberInfo.txt (Ben kuyruk ucunu COLUMN_NAME ve doğrudan yolu, MemberInfo, MemberInfo.txt ve MemberInfo.txt.txt çalıştım
Geçerli dizindir ve ne yaptığım önemli değil, hala açılmıyor.
Herhangi bir öneriniz var mı? Düzenleme
: Eğer AC tarzı dize için dosya dönüştürmek durumunda İşte (. Öğeler dahil muhtemelen gerekmez)
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int FindInfo();
int main()
{
//declare
int choice = 0;
char ans = '\0';
auto stuff = 0;
const int SEARCH_CHOICE = 1;
const int ADD_CHOICE = 2;
const int EDIT_CHOICE = 3;
const int DISPLAY_CHOICE = 4;
const int QUIT_CHOICE = 5;
ifstream inputFile;
string filename;
cout << " Tablerock Member Services" << endl;
cout << "***************************\n\n" << endl;
cout << " Please enter the name of the member file: ";
cin >> filename;
inputFile.open(filename.c_str());
if(inputFile)
{
do
{
cout << "\n";
cout << " 1. Find a member's information" << endl;
cout << " 2. Add a member to the database" << endl;
cout << " 3. Edit a member's information" << endl;
cout << " 4. Display all records" << endl;
cout << " 5. Quit" << endl;
cout << " Please choose an option from the menu:";
cin >> choice;
switch(choice)
{
case SEARCH_CHOICE:
FindInfo();
cout << " Would you like to choose again?";
cin >> ans;
break;
case ADD_CHOICE:
cout << " You chose option 2." << endl;
cout << " Would you like to choose again?";
cin >> ans;
break;
case EDIT_CHOICE:
cout << " You chose option 3." << endl;
cout << " Would you like to choose again?";
cin >> ans;
break;
case DISPLAY_CHOICE:
cout << " You chose option 4." << endl;
cout << " Would you like to choose again?";
cin >> ans;
break;
case QUIT_CHOICE:
cout << " Press Q to exit the program or y/Y to select another option.";
cin >> ans;
break;
}//end switch
}while(ans == 'y' || ans == 'Y');
}
else while (inputFile == false)
{
cout << "There was an error opening the file. \n Please enter the filename: ";
cin >> filename;
inputFile.open("filename");
}
return 0;
}
int FindInfo()
{
const int SIZE = 21;
char lname[SIZE];
char ans = '0';
cout << "\n\n Search for a member:" << endl;
cout << "\n Please enter the last name of the member you are trying to find." << endl;
cout << " Last Name: ";
cin >> lname;
cout << " You entered " << lname << "." << endl;
cout << " Is this correct? (y/n)";
cin >> ans;
if(ans == 'y' || ans == 'Y')
{
cout << " Great! Please wait while we find the member in our database..." << endl;
}
else while(ans == 'n' || ans == 'N')
{
cout << " Please enter the last name of the member you are trying to find." << endl;
cout << " Last Name: ";
cin >> lname;
cout << " You entered " << lname << "." << endl;
cout << " Is this correct? (y/n)";
cin >> ans;
if(ans == 'y' || ans == 'Y')
{
cout << " Great! Please wait while we find the member in our database..." << endl;
}
}
return 0;
}
C++ 11, ['open' yönteminde] 'std :: string' kullanımı için destek ekler (http://en.cppreference.com/w/cpp/io/basic_ifstream/open). Derleyiciniz bir ton yeni özellikte eksik olduğunuzu desteklemiyorsa, mümkünse yükseltmeye değer. – tadman
Bu proje için Visual Studio 2012 kullanıyorum. – lynnrhyann
İdeal olarak 2015'e geçebilir ve sadece C++ 11'deki gelişmelerden değil C++ 14'den de yararlanabilirsiniz. Orada bir sürü yeni şey var (https://msdn.microsoft.com/en-us/library/hh567368.aspx?f=255&MSPPError=-2147217396). – tadman