
-----------------------------------
Srlancelot39
Wed Feb 09, 2011 12:49 am

Spaces in strings - how?
-----------------------------------
I am making a program that may result in the user entering a string containing spaces, and I need the program to accept the entire input (including spaces and characters after a space) and store it in the variable.  Currently the program is carrying over words after a space into the next get.
Example (pseudocode and output):

get var1

(input: word1 word2)

get var2 - this ends up taking word2 as its value

print var1,var2

output: word1,word2


I know this example looks like crap, but basically, the program is carrying over the input.  How do I get it so that var1 is holding "word1 word2"?

Thank you!

-----------------------------------
Tony
Wed Feb 09, 2011 1:03 am

RE:Spaces in strings - how?
-----------------------------------
I think you are missing some arguments there... http://www.cplusplus.com/reference/iostream/istream/get/
[code]
char str[256];
cin.get (str,256);
[/code]
Should work with spaces.

-----------------------------------
Srlancelot39
Wed Feb 09, 2011 1:19 am

RE:Spaces in strings - how?
-----------------------------------
do i have to use 'str' or is that where my variable name goes?

-----------------------------------
Srlancelot39
Wed Feb 09, 2011 1:23 am

Re: Spaces in strings - how?
-----------------------------------
// Assignment1 2.13.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include 
#include 
#include "iostream"
#include "conio.h"
#include 

using namespace std;
int main()
{
	string driveletter;
	char pathname[256];
	string filename;
	string extension;
	cout  extension;
	cout 