Spaces not working.

We are trying to make the console type what the user inputs but when the user uses a space it only uses what is before the space.

our code is:

#include <iostream>
#include <cmath>

int main()
{
using namespace std;
cout << "What do you want to spam?(no spaces)" << endl;
int x;
char input[20];
cin >> input;
for (x=0;x<2147000000;x++)
cout << input;

system("pause");
return 0;
}






also, help on getting it to work on microsoft word would help too. we are using the Dev C++ compiler.
cin stops reading at the space, use getline http://www.cplusplus.com/reference/string/getline/

scaf wrote:
also, help on getting it to work on microsoft word would help too. we are using the Dev C++ compiler.


What do you mean getting it to work on Word, what are you trying to do?
If you mean making it into a word document, then this would be non trivial, and require an 3rd party library, possibly proprietary.

On the other hand, you are happy to make it into a plain text file, you could use <fstream>. Then you can write to a file pretty much as easily as writing to standard output, cout. Read about <fstream> and files in C++ here: http://cplusplus.com/doc/tutorial/files/.

If this isn't what you mean then feel free to ignore this post. If on the other hand, it is, bear in mind that the file created would be length_of_user_input times 2 billion, i.e. a five character input would (I think) result in a 10GB file.
Last edited on
Thank both of you, that solved both of the issues.
Glad to be of help :)

If you really are going to write that to a file, I very much recommend you reduce the loop count to maybe a few hundred. As I said, the resulting file is going to be *huge* if you write the string to it 2 billion times.
I know, i was using 2147000000 as a test number.
Topic archived. No new replies allowed.