功能未打印到日志文件 [英] Function Not Printing To Log File

查看:174
本文介绍了功能未打印到日志文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在程序的main()中运行的日志文件.我也有一个在main()中调用的函数.该功能可以正常工作并打印到控制台,但是日志文件也可以正常工作.函数的返回值不会打印到日志文件中,我是否需要为此做些事情?该功能.

I have a log file that runs in the main() of the program. I also have a function that is called within the main(). The fuction works fine and prints to console, the log file works fine as well, however; the return values from the fuction don''t print to the log file, is there something specil that I have to do for this to happen? The function.

void decode_tcp(char *_packet)
{
	TCPHEADER *tcp_header = (TCPHEADER *)_packet;
    BYTE flags = ( ntohs(tcp_header->info_ctrl) & 0x003F );
	if ( flags & 0x01 ) // FIN
		printf("\n   FIN " );
		myfile << "\n   FIN " ;
	if ( flags & 0x02 ) // SYN
		printf("\n   SYN " );
		myfile << "\n   SYN " ;
	if ( flags & 0x04 ) // RST
		printf("\n   RST " );
		myfile << "\n   RST " ;
	if ( flags & 0x08 ) // PSH
		printf("\n   PSH " );
		myfile << "\n   PSH " ;
	if ( flags & 0x10 ) // ACK
		printf("\n   ACK " );
		myfile << "\n   ACK " ;
	if ( flags & 0x20 ); // URG
		printf("\n   URG " );
		myfile << "\n   URG " ;
		printf("\n   Sequence Number  : %lu\n", ntohl(tcp_header->seq_number));
		myfile << "\n   Sequence Number  :"<< ntohl(tcp_header->seq_number);
	}

推荐答案

好的,这本身并不是一个新的解决方案",只是在前一个中有很多评论我不能再遵循是"是不是"的事实了.

因此,如果将原始帖子视为精确",为什么未声明未声明的"myfile"时出现编译错误?您的其他注释显示了在"main()"范围内的"myfile"声明,因此函数"decode_tcp()"应该无法访问该声明,因此应该得到编译错误.如果没有出现编译错误,那么您就不会发布正在使用的确切代码,这会浪费我们的时间.

如您现在所说,如果输出到达日志文件,但格式不符合或不符合"printf"输出,请同时发布 both 输出.我无法从这里看到您的终端机,因此除非您在此处显示它,否则我不知道您在看什么.
OK, this is not a new "solution" per se, it''s just that there are so many comments in the previous one that I can''t follow what "is" is "is not" true anymore.

So, if the original post is to be taken as "exact", why are you not getting compile errors on ''myfile'' being undeclared? Your additional comments show the declaration of ''myfile'' inside the scope of ''main()'' so it should be inaccessible to the function ''decode_tcp()'' so you should get compile errors. If you do not get compile errors, then you are not posting the exact code being used and are wasting our time.

If, as you now say, the output is getting to the log file but is in a format you don''t like or doesn''t match the ''printf'' outputs, then post both outputs. I cannot see your terminal from here so I have no idea what you are looking at unless you show it here.


您是否注意到这些行有什么问题,
Do you notice what is wrong with these lines,
if ( flags & 0x01 ) // FIN
    printf("\n   FIN " );
myfile << "\n   FIN " ;


压痕得到纠正后?
我是否可以建议您始终使用大括号将ifdowhile等目标括起来.


once the indentation has been corrected?
May I suggest you always use braces to bracket the target of if, do, while etc.


我什么也看不到打开/创建"myfile"甚至声明它的文件.

1)如果您不将文件与流相关联,您认为输出在哪里?

2)如果您未发布完整的相关代码,则不会获得任何帮助
I don''t see anything that Opens / Creates "myfile" or even declares it.

1) if you don''t associate a file with the stream, where do you think the output goes?

2) if you don''t post the entire relevant code, you won''t get any help


这篇关于功能未打印到日志文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆