Thread: I don't understand what it main whitespace separated words

  1. #1
    Registered User
    Join Date
    Sep 2009
    Posts
    1

    I don't understand what it main whitespace separated words

    Dear developers, programmers

    I would like to written this program whit this problem:

    Create a program that opens a file and counts the whitspace-separated words in that file

    Oke this is my code:

    Code:
    #include <string>
    #include <iostream>
    #include <fstream>
    #include <iomanip>
    using namespace std;
    
    int main()
    {
        ifstream in("test.cpp");
        string s, line;
        while(getline(in,line))
       {
             / I don't know what I can put here
       }
       //cout << line << s;
       return(0);
    }
    Can someone help my what that main en coded this problem?
    "counts the whitspace-separated words in that file"

    Thanks
    S

  2. #2
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    you want to count the occurance of characters in teh strign array that are not alphanumeric or symbols, i.e. spaces, tabs, possibly underscores.

  3. #3
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    Whitespace is space/tabs/newline characters. I'd suggest the simple use of operator>> to extract whitespace delimited words from your file coupled with a counter.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. what to do with the main window
    By stallion in forum Windows Programming
    Replies: 2
    Last Post: 01-28-2003, 08:58 PM
  2. counting words in string
    By Unregistered in forum C Programming
    Replies: 9
    Last Post: 05-30-2002, 04:10 AM
  3. void main
    By Shadow in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 05-29-2002, 07:08 PM
  4. void main(), int main(), argc, argv[]????
    By Jonny M in forum C Programming
    Replies: 3
    Last Post: 03-06-2002, 09:12 AM
  5. void or int for main?:)
    By bigtamscot in forum C Programming
    Replies: 13
    Last Post: 09-27-2001, 03:11 AM

Tags for this Thread