'write all words from string containing substring C++
I need to print all words from the text file which includes substring, how can I add to the code? The code which I have is printed below
#include <iostream>
#include <fstream>
#include <bits/stdc++.h>
using namespace std;
int main()
{
ifstream f("lab.txt");
fstream n("lab2.txt", ios::out);
if (f.is_open()) {
string s;
string word = "";
string substring ="ab"
while(getline(f, s)) {
for (auto x : s)
{
if (x == ' '|| x==','|| x=='!'|| x=='?'|| x==':'|| x==')'|| x=='(')
{
n << word << endl;
word = "";
}
else {
word = word + x;
}
}
n << word << endl;
word="";
}
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|