У меня есть текстовый файл с именем myfile.txt, в котором перечислено содержимое диска D:\. В моей программе есть функция, которая читает myfile.txt. Он будет извлекать имена файлов из расширения .txt. Я не очень хорошо разбираюсь в C ++, не могли бы вы сделать его "простым"? Меня смущает начальная позиция подстроки, поскольку я могу узнать, откуда она начнется.
#include<iostream>
#include<string>
#include<fstream>
using namespace std;
int main(void)
{
system("cls");
string temp;
fstream file;
file.open("D:\\myfile.txt", ios::in);
while( file.good() )
{
file>>temp;
string str2, str3;
size_t pos;
str2 = temp.substr (4,4); // confused with this
pos = temp.find(".txt"); // position of ".txt" in temp
str3 = temp.substr (pos);
cout << str2 << ' ' << str3 << endl;
}
system("pause");
return 0;
}
find / -type f -iname "*.txt" > textFiles.txt- person I82Much   schedule 07.04.2011grep 'txt$' < files.txt > textfiles.txt. - person Robᵩ   schedule 07.04.2011