Problems with spacing in variables

r variable names with spaces
r remove spaces from column
dplyr column names with spaces
how to remove spaces in variable names r
sas datalines with spaces

I am building a citation machine for books. However, I am facing a problem with the citing.Here is my code:

#include <iostream>
using namespace std;
string nameofbook,lauthor,x,fmauthor,year,publisher,citystate;
int main(){
cout<<"Welcome to the citation machine. What do you want to cite?"<<endl;
cin>>x;
if(x == "book"){
cout<<"What is the name of the book?"<<endl;
cin>>nameofbook;
cout<<"What is the last name of the author?"<<endl;
cin>>lauthor;
cout<<"What is the first and middle name of the author in abbreviations?"<<endl;
cin>>fmauthor;
cout<<"Which year is the book published?"<<endl;
cin>>year;
cout<<"Who is the publisher?"<<endl;
cin>>publisher;
cout<<"Which state or city is the publisher located at?"<<endl;
cin>>citystate;
cout<<"You are done!"<<endl;
cout<<"The citation is"<<endl;
cout<<lauthor;
cout<<" ";
cout<<fmauthor;
cout<<" ";
cout<<"(";
cout<<year;
cout<<")" ;
cout<<" ";
cout<<nameofbook;
cout<<" ";
cout<<citystate;
cout<<":";
cout<<" ";
cout<<publisher;

}


return 0; 
}

When I compile and run this in Dev C++, It gives me this:

Welcome to the citation machine. What do you want to cite?
book
What is the name of the book?
Catching Fire
What is the last name of the author?
What is the first and middle name of the author in abbreviations?
Collins S.
Which year is the book published?
Who is the publisher?
Scholastic Corporation
Which state or city is the publisher located at?
You are done!
The citation is
Fire Collins (S.) Catching Corporation: Scholastic
--------------------------------
Process exited after 88.09 seconds with return value 0
Press any key to continue . . .

When I let all details be a single word, it becomes:

Welcome to the citation machine. What do you want to cite?
book
What is the name of the book?
Mockingjay
What is the last name of the author?
Collins
What is the first and middle name of the author in abbreviations?
S.
Which year is the book published?
2009
Who is the publisher?
Scholastic
Which state or city is the publisher located at?
NYC
You are done!
The citation is
Collins S. (2009) Mockingjay NYC: Scholastic
--------------------------------
Process exited after 72.02 seconds with return value 0
Press any key to continue . . .

So when all the details are of a single word, it works perfectly. But when any detail becomes more than one word, it takes the first word to answer the question it was supposed to answer and the second word to answer the next question. So how am I supposed to make both words answer the question it was supposed to answer? I would greatly appreciate if anybody can help me to solve this problem.


Instead of doing

cin >> nameofbook;

try

getline(cin, nameofbook);

and similarly for the rest. When you just do cin >> x it will read only up to the next whitespace. If you want to read the whole line you should do getline.

[PDF] 065-2010: Space Management for Text Variables, On the other hand, retaining spaces in variables can be just as much of a problem. For instance, in creating macro variables with the %LET statement,. The spacing between x-coordinates and/or y-coordinates is not equal. In most cases, you encounter this problem when the spacing between latitudes is not equal. The differences between latitudes decreases as you go toward the poles.


You may use getline() instead of cin as it gets a token from string.

 cout<<"What is the first and middle name of the author in abbreviations?"<<endl;

 getline (std::cin, fmauthor); // and as for other qsns

5 How to deal with empty spaces, Warning: Empty spaces in (column) variable names or in variables often cause troubles! 5.1 Empty spaces in variable names. After reading data into R, we should  Spacing in math mode In mathematical mode characters are spaced as if they were part of a single word, regardless of the actual space you insert. This article explains how to insert spaces of different lengths in mathematical mode.


You require to make an input using std::getline(cin,stringName) function which accepts whole line as input until you press a new line character .Getting a string input using cin would break input on occurence of first space character.

Bayesian optimization of variable-size design space problems, Additionally, complex system design problems occasionally present a variable-​size design space. This results in an optimization problem for  The Effects of Spacing and Mixing Practice Problems. The retention benefit due to additional sessions was independent of the benefit due to spacing, and both variables facilitated retention of


Spaces in variable names – Academic Computing, Programmers have tended to work around this issue by using either underscores (“destination_file”, “error_handler”) or camel case (“  If you were to systematically increase the spacing between any two "atoms" that are multiplied together (such as c and x in the example above), you should also be willing to increase the spacing between all other types of "atoms" in order to preserve the overall balance. To claim that this would be a rather tricky enterprise would be a rather strong understatement.


Dual Phase Evolution, Discrete problems are known as combinatorial problems. Their search space is formed by the combinatorics of solutions.5 If we have two variables, X and Y, and​  3-Dimensional Space. The 3-D Coordinate System; Equations of Lines; Equations of Planes; Quadric Surfaces; Functions of Several Variables; Vector Functions; Calculus with Vector Functions; Tangent, Normal and Binormal Vectors; Arc Length with Vector Functions; Curvature; Velocity and Acceleration; Cylindrical Coordinates; Spherical Coordinates; Calculus III. 3-Dimensional Space


Selfadjoint Operators in Spaces of Functions of Infinitely Many , Foreword Interest in the analysis of functions of infinitely many variables has increased considerably in recent years in connection with the problems and the  178 Partial Differential Equations in Two Space Variables 2. Neumann problem: aw - =g(x, y) on aR an where a/an refers to differentiation along the outward normal to aR 3. Robin problem: aw u(x, y)w + ~(x, y) an = "{(x, y) on aR We illustrate these three problems on Laplace'sequation in a square. laplace'sEquation in a Square Laplace'sequation