using peek while prcessing an array?

So im writing an encryption program for my class in school and i want to use the peek function to look for a space and if it is a space put the previous character back into the input stream.
ex) input="Whats going on."
after this process i would like for it to read
"Whatssgoinggon"

this is what i have but
1
2
3
4
5
  for (int i=0; i < size; i++) {
		if (cin.peek (array[i]) == ' ') {
			array[i] = cin.putback (array[i]);
		}
	}

but i keep getting erroor that reads:
"no matching function to call std::basic_istream<char>:peek(char&)"
ive been stumped on this for a while and have been searching with no avail.
Why are you passing a value to peek()? It takes no arguments.
http://www.cplusplus.com/reference/istream/istream/peek/
By default, formatted input of char skips white space.

1
2
3
4
5
6
7
#include <iostream>

int main()
{
    char c ;
    while( std::cin >> c ) std::cout << c ;
}

clang++ -std=c++14 -stdlib=libc++ -O2 -Wall -Wextra -pedantic-errors main.cpp -lsupc++ && ./a.out <<< 'what is going on?'
whatisgoingon?

http://coliru.stacked-crooked.com/a/150061f437b82ac1
Topic archived. No new replies allowed.