counting the white space seperated words?
now. as you can all see by my join date ive been interested in programming for quite some time. and ive probably gone through this multiple tutorials to get nowhere.
i never built a solid foundation. i was using concepts that i didnt understand at all. so im back to basics.
ive been working on the third excercise from TICPP which states
Quote:
3# Create a program that opens a file and counts the whitespace-separated words in that file.
and ive got. thanks to some fstream help from r.stiltskin
Code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main(){
int x;
string msg = "this is a text file";
string spc = " ";
string msg2;
ofstream count_space ("count_space.txt");
count_space<<msg;
count_space.close();
ifstream Count_Space ("count_space.txt");
Count_Space>>msg2;
while (getline(Count_Space, msg2) == spc)
{
x = x++;
};
cout<<msg2 <<endl;
cin.get();
}
and my efforts wont work. i get an error i cant even begin to understand. yet i dont know whats wrong with it?