I was just wondering, how to check how many 't's there are in the sentence?

#include <iostream>
#include <string>
using namespace std;

int main() 
{
    string test = "The man played with the ball in his backyard.";
    return 0;
}

Recommended Answers

All 2 Replies

use a for loop to iterate through the string and count the number of Ts. You need to count both upper and lower cast Ts.

once you do it manually, you'll learn to use the standard algorithm for this std::count(test.begin(),test.end(),'t')

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.