wii anybody plz tell me that how can we count a char in file when it repeats;
bsse007
-3
Light Poster
Recommended Answers
Jump to PostFirst, please use proper English (i.e. not "plz") when posting on Daniweb.
I would use an std::map. Traverse the string a character at a time. If the element doesn't exist in the map, add it to the map as a key with value=1. If it does already exist in …
Jump to PostGood use of the STL, firstPerson. You can make it even shorter by using istream iterators instead of manually loading a string.
#include <algorithm> #include <fstream> #include <iostream> #include <iterator> int main() { std::ifstream ifs("test.txt"); int count = std::count( std::istream_iterator<char>(ifs), std::istream_iterator<char>(), 'A'); std::cout << count << '\n'; …
All 8 Replies
daviddoria
334
Posting Virtuoso
Featured Poster
bsse007
-3
Light Poster
daviddoria
334
Posting Virtuoso
Featured Poster
bsse007
-3
Light Poster
Radical Edward
301
Posting Pro
daviddoria
334
Posting Virtuoso
Featured Poster
mrnutty
761
Senior Poster
Radical Edward
301
Posting Pro
mrnutty
commented:
nice 1
+5
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.