Solved Count characters in input

October 10, 2012 at 11:13:07
Specs: Windows 7
How can you count the characters (spaces included) from the user input?
Preferably having the symbols and numbers included as well.

See More: Count characters in input

Report •


✔ Best Answer
February 3, 2013 at 00:19:48
for(int i = 0; i <= str.length(); i++)
cout << str(i);

^This should work. ;)



#1
October 11, 2012 at 07:21:33
It rather depends upon what function you are using to input characters. Is there a particular reason why you need to count the characters?

Report •

#2
October 12, 2012 at 08:55:30
I agree with ijack. There's a number of ways to do what you want in Win32.
Reading input can be done a number of ways, each with their own trade offs.
● You could call string's std::getline()
● You could call std::cin's getline()
● You could use the low level console input functions, such as ReadConsoleInput()
● You could make a GUI program, and look for WM_CHAR messages

Timing can be done a number of ways as well.
● You could measure the time between the start of input and the end
● You could create a (hidden) window and feed that into a Win32 timer.
● You could create a waitable timer, and wait on it.

How To Ask Questions The Smart Way


Report •

#3
October 12, 2012 at 10:58:37
Razor, care to provide an example?
I'm quite new to c++.

Report •

Related Solutions

#4
October 12, 2012 at 11:04:57
I could, but then it'd be my project, and not yours.

How To Ask Questions The Smart Way


Report •

#5
October 12, 2012 at 11:55:40
lol, come on, just an example as to how i'd start off i do not need a fully functional snippet.

Report •

#6
October 12, 2012 at 12:17:46
Okay, here's your starter. It includes everything you'll need to use the easiest method.
#include <iostream>
#include <string>
#include <ctime>

using std::cout;
using std::cin;
using std::string;
using std::getline;
using std::clock_t;
using std::clock;

int main() {
  //TODO: Your code
  return 0;
}

How To Ask Questions The Smart Way


Report •

#7
February 3, 2013 at 00:19:48
✔ Best Answer
for(int i = 0; i <= str.length(); i++)
cout << str(i);

^This should work. ;)


Report •


Ask Question