I've read a few threads on this site; all seem to provide almost everything I need to complete this project, but I just cannot get there.
What I am trying to do is, instead of reading the raw text from a local text file and counting the word, have the user paste the raw text into the output window and C++ processes and returns the word count. The raw text can be a bunch of paragraphs, not just a line.
Below is my failed attempt, with the input portion commented out. A little bit more than a URL would be greatly appreciated. I've spent a lot of hours on this and failed each time :)
Background: taking a beginners course in C++
#include <string>
#include <fstream>
#include <sstream>
#include <iostream>
const char *FILENAME = "input.txt";
int main()
{
/*
std::cout << "Enter your text: ";
char raw[1000];
std::cin >> raw;
*/
std::ifstream mytext(FILENAME);
if(!mytext)
{
return 1;
}
std::string word;
int totalwords = 0;
int totalcharacters =0;
while(mytext >> word)
{
std::cout << "Found: '" << word << "' with " << word.length() << " character(s)." << std::endl;
totalcharacters = totalcharacters +word.length();
totalwords++;
}
std::cout << "-----------------------------------" << std::endl;
std::cout << "The file has " << totalwords << " words." << std::endl;
std::cout << "The " << totalwords << " words used " << totalcharacters << " characters." << std::endl;
return 0;
}
thanks in advance for your help.