Welcome to Dream.In.Code
Become a C++ Expert!

Join 149,552 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,582 people online right now. Registration is fast and FREE... Join Now!




File I/O Problems

 
Reply to this topicStart new topic

File I/O Problems, It only reads the first word into the file...

Delta_Echo
22 Nov, 2007 - 12:11 PM
Post #1

D.I.C Regular
***

Joined: 24 Oct, 2007
Posts: 480


My Contributions
I just got done reading a tutorial on File I/O (the tutorial only dealt with text files) and i tried something simple.
I wanted to make a program that took the users input and read it to a text file and saved it.
But it only takes the first word before the first space, so can you pls tell me whats wrong?
CODE


#include <iostream>
#include <cstring>
#include <fstream>

using namespace std;

int main()
{
    char sen[100];
    
    ofstream report ( "Rep.txt" );
    
    cin >> sen;
    
    report<< sen << " ";
    report.close();
    cin.get();
}

ty
User is offlineProfile CardPM
+Quote Post

NickDMax
RE: File I/O Problems
22 Nov, 2007 - 12:20 PM
Post #2

2B||!2B
Group Icon

Joined: 18 Feb, 2007
Posts: 2,868



Thanked: 53 times
Dream Kudos: 550
My Contributions
you can't used the formatted input (cin >>) since it will tokenize the input. You can use the cin.get() function or the getline function.

This post has been edited by NickDMax: 23 Nov, 2007 - 09:08 AM
User is offlineProfile CardPM
+Quote Post

Delta_Echo
RE: File I/O Problems
23 Nov, 2007 - 09:00 AM
Post #3

D.I.C Regular
***

Joined: 24 Oct, 2007
Posts: 480


My Contributions
Thanks!
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 1/7/09 09:49PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month