How to separate words on the same line in an .txt file

What I'm trying to do is have an input .txt file with multiple words on one line. I am able to have it produce an output .txt file but I want the words to be on their own lines.

Example:
The .txt will be like:
The man jumps

And I want the output to be:
Case 0:
The
Case 1:
man
Case 2:
jumps

Any suggestions would be appreciated.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include <string>

int main()
{
	std::string input;
	int case_num = 0;
	while (std::getline(std::cin, input))
	{
		std::cout << "Case: " << case_num << '\n';
		case_num += 1;
		std::cout << input << '\n';
	}
	return 0;
}
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include <string>

int main()
{
	std::string input;
	int case_num = 0;
	while (std::cin >> input) // Note: No getline
	{
		std::cout << "Case: " << case_num << '\n';
		case_num += 1;
		std::cout << input << '\n';
	}
	return 0;
}
Thank you so much. That was all I needed.
Topic archived. No new replies allowed.