Counting characters

This is a discussion on Counting characters within the C++ Programming forums, part of the General Programming Boards category; Does anyone know of a code I could use to count the number of characters (or words) in an externel ...

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    31

    Question Counting characters

    Does anyone know of a code I could use to count the number of characters (or words) in an externel text file? I suppose I would use the file to create a string variable first. but I can't think of what I'd use to count the characters (perhaps a search function of some sort?)

  2. #2
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,383
    Use the size() function member of the string to count the size of the string. Subtract the spaces by using the count() algorithm.

    Both functions description can be found here: http://www.cppreference.com/index.html
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  3. #3
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Or if you're using Windows you could use CreateFile() to open a file and then GetFileSize() to get it's size.
    "The Internet treats censorship as damage and routes around it." - John Gilmore

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Counting the characters from each word from a text file
    By flipguy_ph in forum C Programming
    Replies: 6
    Last Post: 04-27-2009, 05:56 PM
  2. Replies: 10
    Last Post: 07-10-2008, 03:45 PM
  3. Help with hw problem: counting characters in a string
    By pinkfloyd4ever in forum C++ Programming
    Replies: 11
    Last Post: 11-04-2007, 10:18 PM
  4. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 04:54 PM
  5. Counting characters
    By tay_highfield in forum C Programming
    Replies: 3
    Last Post: 01-29-2003, 11:54 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21