C++ Making my code actually print out to an output.txt
Hello,
I have managed to make my code create an output.txt file but I'm having issues making it print.
I have this now
1 2 3 4 5 6 7 8 9 10
|
int main()
{
std::ifstream tokens_in( "input.txt" );
std::ifstream dict_in( "dictionary.txt" );
std::ofstream out( "output.txt" );
auto filtered = filter(tokens_in, read_dictionary(dict_in));
for (auto& token : filtered)
std::cout << token << '\n';
}
|
When I run the script it creates an output.txt but doesn't print anything in it. It should be since it's being printed to CMD just fine.
How can I make this print out to an output.txt?
For example:
CMD will print out:
Word1
Word2
word3
word
Because it matched it in dictionary.txt and input.txt but in the output.txt there's nothing there.
It should be since it's being printed to CMD just fine. |
No, because you're not writing to out anywhere.
8 9 10 11
|
for (auto& token : filtered)
{ std::cout << token << '\n';
out << token << '\n'; // Need to write to out as well as cout
}
|
How do you do that? I'm new to this, not familiar with C++ really. This simple project has taken me 3 days and I'm still not done with it.
What would
1 2 3 4
|
for (auto& token : filtered)
{ std::cout << token << '\n';
out << token << '\n'; // Need to write to out as well as cout
}
|
look like if it was written to out like it's suppose to?
(Sorry for asking to be spoonfed, I just honestly have no clue.)
I just gave you the code.
Line 2 writes the token to cout.
Line 3 writes the token to out.
Yes, I just tried it. Thanks so much!
I appreciate it a ton!
Topic archived. No new replies allowed.