我必须每隔一段时间用c ++编写一次。我的问题是如何在字符串中找到字符串?然后保存该行,然后在该行中查找一组数字。例如,我有一个看起来像这样的文本文件。
地址长度名称 87623498 2只狗 12345678 4只猫 98737289 1只鸟
我想搜索“cat”,然后将与之关联的数字(12345678)和(4)存储到不同的变量名称中。这是我写的一些代码,但它并不接近正确。我有一个调用此DLL的.exe。任何帮助表示赞赏! ` #包括 #包括 #包括 #包括 #include
char* File_Path; //Path is sent by another program
char* Name; //value is being sent by another program
unsigned long Address;
int Length;
int found = 0;
{
using namespace std;
std::string Line;
std::ifstream infile;
infile.open (File_Path);
if (infile.is_open())
{
std::ofstream outfile;
outfile.open ("C:\\debug\\test.txt")
while (infile.good() && found == 0)
{
std::getline(infile,Line);
//if (Name is within Line){
/*I want to say IF char* Name = a part of the string line
ie. Name = cat and the string Line is (12345678 4 cat)
Then store the number (12345678 = Address), and
(4 = Length) I hope that makes sense :/
*/
outfile << Line; //output the stored line for debug
outfile << address; //output the stored address for debug
outfile << length; //output the stored length for debug
found = 1;
}
outfile.close();
infile.close();
}
return 0;
}
` 请帮忙!谢谢!