C ++ cout到txt文档 [英] C++ cout to a txt document

查看:86
本文介绍了C ++ cout到txt文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前在使用C ++代码时遇到麻烦.尽管我们已经开始运行它并提示了所需的信息,但是这些信息并未按照我们的需要进行记录.有人可以告诉我如何将输出发送到txt文档等,这样我们就不会丢失它?我尝试过在线遵循一些指南,但是我很迷茫.我不确定是否会有所帮助,但这是我们正在努力解决的代码:

I''m currently having trouble with a c++ code. While we''ve gotten it to run and cout the information that''s needed the information isn''t recorded as we need. Could someone tell me how to have the output be sent to a txt document or the like so we won''t lose it? I''ve tried following some of the guides online but I''m rather lost. I''m not certain if it will help but here is the code we''re struggling with:

#if defined( _WIN32 )
#define _WIN32_WINNT 0x0400			// avoid winsock problem
#include <iostream>
using std::cout;
#else
#include <unistd.h>
#include <iostream.h>
#endif

#include 

// Turn off the following to use a tracker emulator instead of
// a real tracker
//#define USE_REAL_TRACKER

//
// Main function for the demo.
//
int main( int argc, char *argv[] )
{

	vhtIOConn *gloveDict;
	vhtCyberGlove *glove;
	vhtIOConn *trackerDict;
	vhtTracker *tracker;
	try
	{
		// Connect to the glove.
		gloveDict = vhtIOConn::getDefault( vhtIOConn::glove );
		// Expand the CyberGlove connection to the CyberTouch capabilities.
		glove = new vhtCyberGlove(gloveDict);

		// Connect to the tracker
#if defined( USE_REAL_TRACKER )
		trackerDict = vhtIOConn::getDefault( vhtIOConn::tracker );
		tracker = new vhtTracker( trackerDict );
#else
		tracker = new vhtTrackerEmulator();
#endif
	}
	catch (vhtBaseException *e)
	{
		printf("Error: %s\nPress <enter> to exit.\n", e->getMessage());
		getchar();
		return 0;
	}

	//
	// The demo loop: get the finger angles from the glove.
	//
	vhtTransform3D trackerXForm;
	vhtVector3d	position;
	vhtQuaternion  orientation;
	vhtVector3d	axis;
	double baseT = glove->getLastUpdateTime();

	while( true ) {
	// update data from the physical device
	glove->update();
	tracker->update();

	// Get update time delta
	cout << "deltaT: " << glove->getLastUpdateTime() - baseT << "\n";

	// Get joint angles
	cout << "Glove: \n";
	for( int finger = 0; finger < GHM::nbrFingers; finger++ ) {
		cout << finger << " ";
		for( int joint = 0; joint < GHM::nbrJoints; joint++ ) {
		cout << glove->getData( (GHM::Fingers)finger, (GHM::Joints)joint ) << " ";
		}
		cout << "\n";
	}

	// Get tracker data as a vhtTransform3D in world frame
	tracker->getLogicalDevice(0)->getTransform( &trackerXForm );

	// print translation and orientaion
	trackerXForm.getTranslation( position );
	trackerXForm.getRotation( orientation );
	orientation.getAxis( axis );

	cout << "Tracker: \n";
	cout << position.x << " " << position.y << " " << position.z << "\n";
	cout << axis.x << " " << axis.y << " " << axis.z << " " << orientation.getAngle() << "\n";

	// wait for 100ms
#if defined(_WIN32)
	Sleep(100);
#else
	usleep( 100000 );
#endif

	}

	return 0;
}</enter></iostream.h></unistd.h></iostream>

推荐答案

对于控制台应用程序,只需在运行时将输出重定向到文本文件即可.

C:\ folder> someapp.exe> output.log
For console apps, just redirect the output to a text file when you run it.

C:\folder> someapp.exe > output.log


这篇关于C ++ cout到txt文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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