我一直在尝试如何获取用户输入来命名将要创建的文件,我一直在尝试创建一个日记应用程序,该应用程序可以做笔记并将其存储在文件中。反正这里是代码
#include "main.h"
#include <string>
char Start;
int main()
{
int input;
std::fstream fFile;
std::cout << "*******" << std::endl;
std::cout << "Journal" << std::endl;
std::cout << "*******" << std::endl;
std::cout << "Enter any value to continue..." << std::endl;
std::cin >> Start;
system("CLS");
std::cout << "Hello" << std::endl;
std::cout << "....." << std::endl;
std::cout << "" << std::endl;
std::cout << "[1] Create New Note" << std::endl;
std::cout << "[2] Browse Note Libary" << std::endl;
std::cin >> input;
if (input == 1)
{
std::string NoteName;
std::cout << "Enter New Notes Name" << std::endl;
std::cin >> NoteName;
fFile.open("NoteName.txt"); // Here is what I can't figure out
fFile << "test" << std::endl;
fFile.close;
}
if (input == 2)
{
}
}
Main.h仅包含并使其包含,因此我可以调用main函数(:
简单
fFile.open(NoteName);
或者如果您想在用户输入的名称后添加“ .txt”,则>]
fFile.open(NoteName + ".txt");
您尝试的方法称为字符串插值。它适用于某些语言,但不适用于C ++。