【发布时间】:2012-12-14 08:41:23
【问题描述】:
非常简单的程序,不知道为什么它不起作用:
#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;
}
基本上它应该打印该句子 65535 次,然后将其保存到 txt 文件中。但是 txt 文件只有一个从 1 到 65535 的数字列表,没有文字或格式。有任何想法吗?感谢您的帮助。
【问题讨论】:
-
逗号运算符:不知何时引起混乱!
-
在这里阅读如何使用逗号运算符。 stackoverflow.com/questions/12824378/…
-
谢谢它现在可以工作了,但是我犯了一个错误,我最多只能有 64 个数字,而且它们需要在 10001 和 65535 之间随机。有人知道吗?
标签: c++