2017-07-25 34 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保留最後<<

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