how to solve this programming problem ?



I have to solve this programming exercise and I don't know how to do it.

Write a program to read strings from the standard input, concatenating what is read into a large concatenated string next ( ok I wrote this program and it works properly ), change the program to separate adjacent input strings by a space ( problem with the second part ). In my book i learnt the difference between the string input operator and the getline function, size member function, empty , but i can't undersand how to read two adjacent strings and how to separate them, could you help me ? P.S : I'm a c++ beginner so i know just a very very little bit of the language.

this is my code of the first part of the program
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream> 
#include <string> 

int main()
{
	std::string word; 
	std::string chain; 

	while (std::cin >> word) {

		chain += word; 
	}
	
	std::cout << chain << std::endl; 
	
	

	system("pause"); 
	return 0; 

}


On line 11, you currently have:

chain += word;

Just change it to:

chain += word + " ";
Registered users can post here. Sign in or register to post.