C++ 移除字串的問題 高手請進

2009-04-01 5:51 pm
我想要將下面txt檔案裡面的文字

把<>中的都移除


跨年時吃火鍋好爽

最後會變成

跨年時吃火鍋好爽

不知道C++有什麼方法可以來移除了

麻煩C++高手幫忙

感謝
更新1:

我是要連<>裡面的東西都移並刪除 請問這樣該怎麼做呢 謝謝

回答 (2)

2009-04-01 11:21 pm
✔ 最佳答案
#include <iostream>
#include <stdlib.h>
#include <fstream>
using namespace std;
int main(int argc, char* argv[])
{
fstream file,file1;
file.open("past.txt",ios::in);
file1.open("new.txt",ios::out);
char str;
if(file)
if(file1)
while(!file.read(&str,sizeof(char)).eof())
if(str!='<'&&str!='>')
file1.write(&str,sizeof(char));

file.close();
file1.close();
system("pause");
return 0;
}
past.txt是有含<>
new.txt不含<>
有什麼問題再問吧!

2009-04-01 15:55:02 補充:
#include <iostream>
#include <stdlib.h>
#include <fstream>
using namespace std;
int main(int argc, char* argv[])
{
bool BOOL_writ=true;
fstream file,file1;
file.open("c.txt",ios::in);
file1.open("d.txt",ios::out);
char str;
if(file)
if(file1)

2009-04-01 15:55:21 補充:
接續
while(!file.read(&str,sizeof(char)).eof())
{
if(str=='<')
BOOL_writ=false;
if(BOOL_writ)
file1.write(&str,sizeof(char));
if(str=='>')
BOOL_writ=true;
}
file.close();
file1.close();
system("pause");
return 0;
}

2009-04-01 15:55:40 補充:
有什麼問題再問吧!
2009-04-01 7:08 pm
Sorry, don't really understand the question. Don't you mean removing all the "<" and ">" signs?


收錄日期: 2021-04-30 13:00:14
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20090401000010KK02094

檢視 Wayback Machine 備份