我有这堂课:
public ref class Database
{
private:
String ^username, ^password, ^name, ^telNum, ^celNum, ^address, ^location;
String ^tempUser;
public:
Database(String^, String^, String^, String^, String^, String^, String^);
bool ifFileExists();
bool ifAccountExists();
void CreateAccount();
};
我定义了这个:
bool Database :: ifAccountExists(){ifstream File(“Database.txt”, 的ios_base ::在);
文件>> tempUser; //这一行得到错误我觉得有问题 字符串^
//返回true或false}
如何解决此问题?
答案 0 :(得分:2)
正如汉斯指出的那样,您需要向托管方提供帮助,或者使用托管类型编写整个代码,如下所示:
bool Database::IfAccountExists()
{
if (System::IO::File::Exists(L"Database.txt"))
{
array<System::String ^> ^lines = System::IO::File::ReadAllLines(L"Database.txt");
for each(System::String ^line in lines)
{
array<System::String ^> ^tokens = line->Split('|');
for each (System::String ^token in tokens)
{
// if found
// return true;
}
}
}
return false;
}