#include <fstream>
#include <iostream>
using namespace std;
int main() {
char *c=",";
string str;
int j,t;
ifstream fin;
fin.open("txt.txt");
t=0;
while (!fin.eof()) {
j=0;
getline(fin, str);
for(int i=0;i<str.length();i++){
if (*c==str[i]) j++;
cout<<"Кол-во запятых в строке: "<<t+1<<" :"<<j<<endl;
}
t++;
}
fin.close();
return 0;
}
#include <iostream>
#include <fstream>
#include <algorithm>
int main(int, char**) {
char symbol = ',';
std::ifstream input_file("txt.txt");
int line_number = 0;
std::string current_line;
while (std::getline(input_file, current_line)) {
auto symbols_in_string = std::count(current_line.begin(), current_line.end(), symbol);
std::cout << "'" << symbol << "' in line " << line_number + 1 << ": " << symbols_in_string << std::endl;
line_number += 1;
}
return 0;
}