Click here to Skip to main content
15,031,193 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
#include <fstream>
int main()
    while(myFile >> a)
        if(a ............'C')
    cout<< ........ <<"\n";
    return 0;

What I have tried:

I tried ... Couldn't run it .. Because I didn't understand how to complete the program... I find counting is hard to understand
Updated 8-Feb-16 10:06am
"Could not run it" cannot be classified as what have you tried. What's the use of having "What I have tried" section without showing what you have tried? What's the use of showing gibberish instead of real code sample?
Stefan_Lang 9-Feb-16 4:30am
I don't know what you mean by What do you mean you don't know how to complete the program? What is missing?

Do you know how to write build and run a C/C++ program at all?
Stefan_Lang 9-Feb-16 6:28am
P.S.: That's a quite neat article that SA linked to above. Be sure to check it out. If you really don't feel like it, the long and short of it is this:

If you never at least try to find the solution to particular problems to the limits of your ability to look up fields of information that you are lacking, then you will, ultimately, never learn to solve any problem. What's more, if you learn to solve a problem by yourself, you will later be able to solve similar problems with minimal effort.

The question, "What did you try" has a double prupose: (1) it urges you to try and come up with your own solution or attempt of a solution (2) once you did at least try, we will be able to gauge your level of understanding based on how far you got, and then we will be better able to explain the next steps. More importantly, we won't waste time (a lot of time, potentially) explaining those steps that you already know.

This is pure homework. Please refer to your course notes or ask your teacher. This is a really easy exercise. So give it a try. Counting is not difficult at all. Don't tell yourself, "I can't do this"! This will make it even more difficult. Study your course notes and it will be relatively easy.
Have a look at std::count, std::iostream_iterator and std::ifstream. Using these three chunks of the standard library you can do what you want in two lines of code - three if you want to have an exception thrown if the file failed to open.
nv3 9-Feb-16 4:23am
His assignment was to fill in the dotted spaces ;-)
Aescleal 10-Feb-16 4:06am
I know, but he's not going to learn anything messing around with fill in the blanks rubbish like that. It might help someone that wants to do it seriously.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900