| primecodz (15) | |||||
|
I am trying to create a program that allows the user to do 2 things (create a new file in the current directory, or search a file and display the word count) The word count works fine but when I try to allow the user to create a file it starts going wrong. I first ask the user to input a filename, and then enter some initial data into a string variable. That string variable gets passed to the createFile() function which takes care of entering the data into the file. When I run this program I enter the file data I wish to put in the created file, say for example " Hello File Data" and when I look into that file once its been created there is only the first word ("Hello") in the case of this example. Here is the code: The main function:
The create filefunction:
Please help! :) Thanks | |||||
|
|
|||||
| vichu8888 (176) | |
|
replace cin>>fileData with getline(cin,fileData); It will read the whole line and store in it the fileData variable. if u get errors, use like this cin.ignore(); getline(cin,fileData); | |
|
|
|
| primecodz (15) | |
| thanks, but when I use getline() it doesn't let me enter data... it just skips to say you have entered the data successfully and just puts nothing in the file | |
|
|
|
| primecodz (15) | |
|
nvr mind I got it with cin.ignore() :) ty very much | |
|
|
|