← Back to Streams
Question 619
Split by Parity
Split by Parity
Write a functionvoid splitByParity(const string& src, const string& evens, const string& odds)that reads all the whitespace-separated integers from the filesrcand writes every even integer to the fileevensand every odd integer to the fileodds, in the order they were read. Each output file is created (truncated) and holds exactly one line: its integers separated by single spaces, no space before the first, followed by a newline. Print nothing tocout. Every test source has at least one even and one odd number. The test creates the source file, calls your function, printsEvens:a space and the even count, a space,Odds:a space and the odd count, then prints every line of the evens file and then the odds file. For a source containing1 2 3 4 5(see Expected Output). Do NOT write a main function.
Expected Output:
Evens: 2 Odds: 3 2 4 1 3 5 Evens: 2 Odds: 2 10 8 7 3
= newline. The output ends with a newline — print one after the last line.
Hints4 available
Sign in to use hintsTopics:
Streamsofstream
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cout, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.