A
arnuld
/* C++ Primer 4/e
* section 3.2 - String Standard Library
* exercise 3.8
* STATEMENT
* write a programme to read strings from standard input, concatenate
all of them * in one string where each input string is seperated by
whitespace and then print it. */
#include <iostream>
#include <string>
int main()
{
std::string input_string, final_string;
while(std::cin >> input_string)
if(final_string.empty()) // without "if" we will get a
whitespace
final_string += input_string; // at the beginning of final_string.
else
final_string = final_string + " " + input_string;
std::cout << final_string << std::endl;
return 0;
}
it works fine
-- http://arnuld.blogspot.com
* section 3.2 - String Standard Library
* exercise 3.8
* STATEMENT
* write a programme to read strings from standard input, concatenate
all of them * in one string where each input string is seperated by
whitespace and then print it. */
#include <iostream>
#include <string>
int main()
{
std::string input_string, final_string;
while(std::cin >> input_string)
if(final_string.empty()) // without "if" we will get a
whitespace
final_string += input_string; // at the beginning of final_string.
else
final_string = final_string + " " + input_string;
std::cout << final_string << std::endl;
return 0;
}
it works fine
-- http://arnuld.blogspot.com