473,396 Members | 1,748 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Having trouble with streams and strings

I'm trying to write a string I entered into the program to a file. I won't explain it though, it's probably easier if I just post the code:

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
string input;
cin >> input;
fstream myupdate ("G:\\Documents\\C++\\myfile.txt", ios:: out | ios::app);
myupdate << update << endl << endl << endl;
myupdate.close();
return 0;
}

Problem is, if I type in a string, the first space I hit is where it ends. For instance, if I type the words in the program window "Work you piece of crap!!!" it would just write "Work" to the file and that's it. Apparently that's all that gets written to the string 'input' and so that's all that gets written. Anyone know how to get everything I type in the program window including spaces put into the variable?
Apr 9 '07 #1
2 1077
sicarie
4,677 Expert Mod 4TB
Yeah, that's actually the way cin is supposed to behave (check out Ganon11's tutorials at the top of this forum), it stops at the first whitespace. I think you would be more happy with the getline() function. Try googling that, and see if its what you're looking for.
Apr 9 '07 #2
Yeah, that's actually the way cin is supposed to behave (check out Ganon11's tutorials at the top of this forum), it stops at the first whitespace. I think you would be more happy with the getline() function. Try googling that, and see if its what you're looking for.
Okay, thanks a a ton!:)
Apr 9 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Penn Markham | last post by:
Hello all, I am writing a script where I need to use the system() function to call htpasswd. I can do this just fine on the command line...works great (see attached file, test.php). When my...
5
by: Alligator | last post by:
And more specifically what is the difference between an InputStream and a BufferedInputStream? When should I use one and when should I use the other? And why is there besides a...
9
by: RebelGeekz | last post by:
I am trying to create objects sent as streams over the wire but I am no expert in javascript, can anybody lend me a hand please? // this works, no problem at all client = {name:'John Doe',...
8
by: bonj | last post by:
hello I hope somebody can help me get my head around this area of 'stream' programming... I know that streams are very fashionable nowadays so hopefully there'll be lots of replies. ;-) ...
22
by: ext_u | last post by:
I'm trying to learn C from "The C Programming Language" (by K&R) and I am about halfway through the first chapter. I am using Miracle C as my text editor and compiler. Up until this point...
1
by: Chris | last post by:
I'm reading up on streams and I have two articles that seem to conflict with each other. One article describes streams and lists a few of the major ones (FileStream, Memory Stream, Network...
5
by: Just Me | last post by:
Using streams how do I write and then read a set of variables? For example, suppose I want to write into a text file: string1,string2,string3 Then read them later. Suppose I want to write...
4
by: Rafał Maj Raf256 | last post by:
Hi, I wrote few filters working on streams of bytes, in example enciption, UTF-8 decoding and such. Now I wonder how can I turn them into classes derived from std::stream(?) or in other way to use...
4
by: Kza | last post by:
Hi, just in the process of maintaining some software that used some funy old string library and char*s , and we are updating everything to use std::strings. (or should I say std::basic_string<>s) ...
4
by: floppyzedolfin | last post by:
Hello! I'm actually encoding an encryption / decryption program. The encryption programes takes a file path in parameter, and encrypts the contents of the file and stores that into another file. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.