gpt4 book ai didi

c++ - 将文本文件附加到 Visual Studio 项目...?

转载 作者:行者123 更新时间:2023-11-28 03:51:59 25 4
gpt4 key购买 nike

我几乎完成了一项家庭作业,但我对其中的一个方面感到非常厌烦。该程序的目的是读入一个文本文件,然后进行分析。现在,如果我在我的电脑上,我可以输入文件的完整路径,它运行良好。

但如果我的教授试图运行它,它就不会正常运行。我尝试提示用户输入完整路径,但没有用。我尝试将文本文件附加到 .exe,但我认为我做的不对。

有人有什么建议吗?

//int bookinput = 0;
//string whichbook;
//ifstream bookread;
//ifstream bookread(whichbook.c_str());
//cout << "Welcome to the book analysis program.\n";
//cout << "Please type in the full path of the book, remembering to double backslashes: ";
//cin >> whichbook;
//
//if(bookinput == 1){
// bookselect = "1984.txt";
//}
//else if(bookinput == 2){
// bookselect = "conneticutYankeeInKingArthursCourt.txt";
//}
//

//bookread.open(bookselect.c_str());
//bookread.open(whichbook.c_str());

bookread.open(whichbook.c_str());

if(bookread.is_open()){
std::cout << "opening book\n\n";
if(bookread.good()){
cout << "opening of book successful :D";
}
while(bookread.good()){ //reads to end of file
string input;
//getline(bookread, input);
bookread >> input;

//only add alphanumerical strings to the word list
if (isAlphaNumerical(input))
{
words.push_back(input);
}
}
}

最佳答案

问题是:

cout << "Please type in the full path of the book, remembering to double backslashes: ";

双反斜杠仅对 C++ 编译器有意义。当您提示用户输入路径时,编译器不参与,不应使用双反斜杠。 (而且字符串输入不能用\t表示制表符等,除非你后面做特殊处理)

关于c++ - 将文本文件附加到 Visual Studio 项目...?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5163841/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com