"and also. i seen it easy to just ad cout<<x + 1;"
this is what i mean by that.
heres the last bit of code
Code:
while(1)
{
Count_Space >> msg;
if(Count_Space.fail()) break;
x++;
};
cout<<"string has"<<x+1 <<"words in it";
cin.get();
return 0;
}
ive put the return in.
and i cheated by adding a 1 to whatever 'x' was. to make up for the extra word in there. but clearly this is cheating.
and while im here. and i think itd be a more then easy question to answer. why wont my 'cin.get();' wait for the keypress? it just closes.
Code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main(){
int x =0;
string msg;
string msg2;
cout<<"please enter a string\n";
cin>>msg;
ofstream count_space ("count_space.txt");
count_space<<msg;
count_space.close();
ifstream Count_Space ("count_space.txt");
Count_Space>>msg2;
while(1)
{
Count_Space >> msg;
if(Count_Space.fail()) break;
x++;
};
cout<<"string has"<<x<<"words in it";
cin.get();
return 0;
}
perhaps i need to close the file im working with?