Instead of printing value in main, Try this :
//call this from main
output_1(str, c);
output_2(str, c);
Then:
void output_1(string s, char c) {
int count = 0;
for (int x = 0; x < s.length(); x++)
if (s[x] == c)
count++;
cout<< count<<endl;
}
void output_2(string s, char c) {
for (int x = 0; x < s.length(); x++) {
if (c == s[x]){
cout << x << " ";
}
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…