cpp文件 按运行顺序输入同一个文本文件 怎么修改 帮忙帮忙,想跟你请教个问题:

china10nan 发布于 2013/08/30 08:35
阅读 102
收藏 0

@小耶果 你好把多个

.#include "stdafx.h"
#include <fstream>
using namespace std;

#ifndef CLEANUP1_H_
#define CLEANUP1_H_


class noisy
{
 
 static int i;
 int objum;
 enum { sz = 40 };
 char name[sz];
public:
    
 noisy(const char* nm = " array elem");
 ~noisy();
 static void* operator new[](size_t sz);
 static void operator delete [](void* p);
};
#endif

 

#include "stdafx.h"

#include "..\cheanup1\cheanup1.h"

#include <fstream>
#include <exception>
#include <string>

using namespace std;

ofstream out("cleanup.txt");

noisy::noisy(const char* nm) throw (int)
{
 objum = i++;
 memset(name,0,sz);
 strncpy(name,nm,sz-1);
 out << "constructing noisy" << objum
  << "name [ "<< name <<" ] " << endl;
 if(objum==5)
 {
  throw int(5);
 }
 if(*nm == 'z')
 {
  throw char('z');
 }
}

noisy::~noisy()
{
 out << " destructing noisy" << objum
  << " name [ "<< name << " ] " << endl;
}

void* noisy::operator new [](size_t sz)
{
 out << "noisy::new[]" << endl;
 return ::new char[sz];
}
void noisy::operator delete [](void* p)
{
 out << "noisy::delete[]" << endl;
 ::delete []p;
}

 

#include "stdafx.h"
#include "..\cheanup1\cheanup1.h"

#include <fstream>
#include <exception>
#include <string>

using namespace std;

int noisy::i =0;
static ofstream out("cleanup.txt");


void unexpected_rethrow()
{
 out << " inside unexpected_rethrow" << endl;
 throw;
}

int main(int argc,char argv[])
{
 if(out==NULL)
 {
  return 0;
 }
 set_unexpected(unexpected_rethrow);
 try
 {
  noisy n1("before array");
  noisy* array = new noisy [7];
  noisy n2(" after array");
 }
 catch(int j)
 {
  out << " caught  j" << j<< endl;
 }

 out << " testing unexpected " << endl;

 try
 {
  noisy n3(" before unexpected");
  noisy n4("z");
  noisy n5(" after unexpected ");
 }
 catch(char c)
 {
  out << " caught c " << c << endl;
 }
}

运行结果如下     但结果有缺少

caught  j5
 testing unexpected
 caught c z
::new[]
constructing noisy1name [  array elem ]
constructing noisy2name [  array elem ]
constructing noisy3name [  array elem ]
constructing noisy4name [  array elem ]
constructing noisy5name [  array elem ]
 destructing noisy4 name [  array elem ]
 destructing noisy3 name [  array elem ]
 destructing noisy2 name [  array elem ]
 destructing noisy1 name [  array elem ]
noisy::delete[]
 destructing noisy0 name [ before array ]
constructing noisy6name [  before unexpected ]
constructing noisy7name [ z ]
 destructing noisy6 name [  before unexpected ]

加载中
0
DTC2
DTC2
请问你有所有的源文件吗?
返回顶部
顶部