全部!我正在尝试找到接受用户输入的最佳方式,为其添加时间戳,然后将其放入具有正确格式的文件中(每行一个时间戳/输入。时间戳的最佳方式是什么,然后放弃将其全部放入文件?谢谢!
以我的准系统代码为例:
#include <iostream>
#include <fstream>
#include <string>
#include <ctime>
using namespace std;
//void passwordCheck()
//{
//
//}
string timestamp(string passwordInput1, string passwordInput2, string passwordInput3, string passwordInput4, string passwordInput5, string passwordInput6, string passwordInput7, string passwordInput8, string passwordInput9, string passwordInput10)
{
time_t now = time(0);
char* dt = ctime(&now);
cout << "The local date and time is: " << dt << endl;
tm *gmtm = gmtime_s(&now);
dt = asctime(gmtm);
}
//void saveToFile()
//{
//
//cout << "I've saved 10 passwords for you." << endl;
//}
int main()
{
ofstream outputToFile;
outputToFile.open("manageMyPasswords.txt");
// Look for easier/cleaner way to do this.
string passwordInput1, passwordInput2, passwordInput3, passwordInput4, passwordInput5, passwordInput6, passwordInput7, passwordInput8, passwordInput9, passwordInput10;
// Put into a function then call back here.
cout << "Welcome to Password Manager!" << endl;
cout << " Enter your first password" << endl;
getline (cin, passwordInput1);
cout << "Enter the next password." << endl;
getline (cin, passwordInput2);
cout << "Enter the next password." << endl;
getline (cin, passwordInput3);
cout << "Enter the next password." << endl;
getline (cin, passwordInput4);
cout << "Enter the next password." << endl;
getline (cin, passwordInput5);
cout << "Enter the next password." << endl;
getline (cin, passwordInput7);
cout << "Enter the next password." << endl;
getline (cin, passwordInput8);
cout << "Enter the next password." << endl;
getline (cin, passwordInput9);
cout << "Enter the next password." << endl;
getline (cin, passwordInput10);
//void saveToFile();
system("pause");
return 0;
}