very simple program, not sure why it isn’t working:
#include <iostream>
#include <fstream>
#include <stdio.h>
using namespace std;
int main ()
{
ofstream myfile ("test.txt");
if (myfile.is_open())
{
for( int i = 1; i < 65535; i++ )
{
myfile << ( "<connection> remote 208.211.39.160 %d udp </connection>\n", i );
}
myfile.close();
}
return 0;
}
Basically it should print that sentence 65535 times, and then save it to a txt file. But the txt file just has a list of numbers from 1 to 65535, no words or formatting. Any ideas? Thanks for help.
If you want to concatenate the output, just pipe your data into two
<<operators, as such:Note that interpolation does not work in that case, so if you want to put your
ivariable into the middle of the string, you have to either split it by hand:Or apply some sort of other interpolation formatting before outputting it.
The problem
The problem exists in your code because in C++,
(a, b)(the comma operator) returnsb. So, in your code it meant you just wroteito a file.