2017-07-25 104 views
0

我收到以下错误,当我试图解决我的文件:MYFILE未声明的标识符

myFile undeclared identifier 

帮助将不胜感激! :)我真的没有看到这个代码中有什么问题。

#include "stdafx.h" 
#include <iostream> 
#include <fstream> 
#include <string> 
#include <windows.h> 


int main() 
{ 
    ofstream myFile; 
    std::string name; 
    std::string password; 
    std::cout << "Enter Name" << std::endl; 
    std::cin >> name; 
    std::cout << "Enter password" << std::endl; 
    std::cin >> password; 
    std::string info = name + ":" + password; 
    myFile.open ("Database.txt"); 
    myFile << (info) << std::endl << ; 
    myFile.close(); 
    Sleep(10000); 
} 

回答

0

您高度重视和使用:std::ofstream myFile申报myFile

,或者你可以在PROGRAMM(外主)的顶部添加using namespace std;,并删除所有std::

如果你想添加文本 “Database.txt”,你用前人的精力:

myFile.open("Database.txt", ios::app); 

的东西是错误的:

myFile << (info) << std::endl << ; 

您sould'nt保留最后<<

您也可能想要返回主内容。