fstream - myFile undeclared identifier -
i following error when try solve file:
myfile undeclared identifier
help appreciated! :) dont see problem in code.
#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); }
you sould use : std::ofstream myfile
declare myfile
or can add using namespace std;
@ top of programm (outside main) , remove std::
.
if want add text "database.txt", sould use :
myfile.open("database.txt", ios::app);
something wrong :
myfile << (info) << std::endl << ;
you sould'nt keep last <<
you may want return in main.
Comments
Post a Comment