C++ Spaces are not being read in my input file? -


input txt file:    joe smith  mary jones  hamid namdar    desired output txt file:    smith joe  jones mary  namdar hamid    output file receive:    smitjoejonesmarynamdarhamid

#include <iostream>  #include <string>  #include <fstream>    using namespace std;    int main()  {  	ofstream output;  	ifstream input;  	string firstname, lastname;    	output.open("lastname.txt");  	input.open("firstname.txt");    	cout << "processing data..." << endl;    	input >> firstname >> lastname;    	cout << firstname << lastname << endl;    	output << lastname << firstname;    	cout << lastname << firstname << endl;    	input >> firstname >> lastname;    	cout << firstname << lastname << endl;    	output << lastname << firstname;    	cout << lastname << firstname << endl;    	input >> firstname >> lastname;    	cout << firstname << lastname << endl;    	output << lastname << firstname;    	cout << lastname << firstname << endl;      	input.close();  	output.close();    	cin.get();  	cin.get();    	return 0;    }

my program required have spaces between names, , though there space in text document, spaces not being read. have idea on should in order have spaces read?

i guessing see spaces in output not getting them. makes think spaces not being read. truth white spaces being read being discarded when use:

input >> firstname >> lastname; 

you need change lines create output to:

cout << firstname << " " << lastname << endl; output << lastname << " " << firstname << endl; 

Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -