gpt4 book ai didi

c++ - 更新 : program shows adress of fstream instead of the text file

转载 作者:行者123 更新时间:2023-11-30 03:43:02 25 4
gpt4 key购买 nike

我将要编写一个程序,询问用户是否要“搜索或转换”文件,如果他们选择convert,他们需要提供文件的位置。

我不知道为什么程序显示文件的地址而不是打开它。

这是我的第一种方法:

#include <fstream>
#include <fstream>
#include <iostream>
#include <string>
using namespace std;

int main()
{

char dateiname[64], kommando[64];

ifstream iStream;


cout << "Choose an action: " << endl <<
" s - search " << endl <<
" c - convert" << endl <<
" * - end program" << endl;
cin.getline(kommando,64,'\n');
switch(kommando[0])
{
case 'c':
cout << "Enter a text file: " << endl;
cin.getline(dateiname,64,'\n');
iStream.open("C://users//silita//desktop//schwarz.txt");
case 's': break;
case '*': return 0;
default:
cout << "Invalid command: " << kommando << endl;
}
if (!iStream)
{
cout << "The file " << dateiname << " does not exist." << endl;
}
string s;
while (getline(iStream, s)) {
while(s.find("TIT", 0) < s.length())
s.replace(s.find("TIT", 0), s.length() - s.find("TIT", 3),"*245$a");
cout << iStream << endl;
}
iStream.close();
}

最佳答案

起初您无法使用== 比较c 字符串。您必须使用 strcmp(const char*, const char*)。您可以在此处找到有关它的更多信息:http://www.cplusplus.com/reference/cstring/strcmp/例如:if (i == "Konvertieren") 必须变成 if(!strcmp(i,"Konvertieren"))

关于c++ - 更新 : program shows adress of fstream instead of the text file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36390919/

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