Hello,

how can I pause the terminal after running the program?
I am using a program that outputs a table of error rates.. but can't see the result.

I used few suggestions on the web but still not working ,

char d;
cin>>d;

not working , what else can I use?

Thank you.

The usual solution is:

cin.ignore(N, '\n');
cin.get();

Where N is a suitably large number for clearing extraneous characters from the stream.

Even when i use this, it tells me that cin is undeclared identifier !! it should not ask for this , isnt it ?

Post all of your code, please. If you're not at the point where you can solve that particular error, I'd much rather just show you the correct fix in your actual code than play twenty questions to figure out what you're doing wrong.

template <unsigned int ImageDimension>
int LabelOverlapMeasures( int argc, char * argv[] )
{
  typedef unsigned int PixelType;
  typedef itk::Image<PixelType, ImageDimension> ImageType;

  typedef itk::ImageFileReader<ImageType>  ReaderType;
  typename ReaderType::Pointer reader1 = ReaderType::New();
  reader1->SetFileName( argv[2] );
  typename ReaderType::Pointer reader2 = ReaderType::New();
  reader2->SetFileName( argv[3] );

  typedef itk::LabelOverlapMeasuresImageFilter<ImageType> FilterType;
  typename FilterType::Pointer filter = FilterType::New();
  filter->SetSourceImage( reader1->GetOutput() );
  filter->SetTargetImage( reader2->GetOutput() );
  filter->Update();

  std::cout << "                                          "
            << "************ All Labels *************" << std::endl;
  std::cout << std::setw( 10 ) << "   "
    << std::setw( 17 ) << "Total"
    << std::setw( 17 ) << "Union (jaccard)"
    << std::setw( 17 ) << "Mean (dice)"
    << std::setw( 17 ) << "Volume sim."
    << std::setw( 17 ) << "False negative"
    << std::setw( 17 ) << "False positive" << std::endl;
  std::cout << std::setw( 10 ) << "   ";
  std::cout << std::setw( 17 ) << filter->GetTotalOverlap();
  std::cout << std::setw( 17 ) << filter->GetUnionOverlap();
  std::cout << std::setw( 17 ) << filter->GetMeanOverlap();
  std::cout << std::setw( 17 ) << filter->GetVolumeSimilarity();
  std::cout << std::setw( 17 ) << filter->GetFalseNegativeError();
  std::cout << std::setw( 17 ) << filter->GetFalsePositiveError();
  std::cout << std::endl;

  std::cout << "                                       "
            << "************ Individual Labels *************" << std::endl;
  std::cout << std::setw( 10 ) << "Label"
            << std::setw( 17 ) << "Target"
            << std::setw( 17 ) << "Union (jaccard)"
            << std::setw( 17 ) << "Mean (dice)"
            << std::setw( 17 ) << "Volume sim."
            << std::setw( 17 ) << "False negative"
            << std::setw( 17 ) << "False positive" << std::endl;

  typename FilterType::MapType labelMap = filter->GetLabelSetMeasures();
  typename FilterType::MapType::const_iterator it;
  for( it = labelMap.begin(); it != labelMap.end(); ++it )
    {
    if( (*it).first == 0 )
      {
      continue;
      }

    int label = (*it).first;

    std::cout << std::setw( 10 ) << label;
    std::cout << std::setw( 17 ) << filter->GetTargetOverlap( label );
    std::cout << std::setw( 17 ) << filter->GetUnionOverlap( label );
    std::cout << std::setw( 17 ) << filter->GetMeanOverlap( label );
    std::cout << std::setw( 17 ) << filter->GetVolumeSimilarity( label );
    std::cout << std::setw( 17 ) << filter->GetFalseNegativeError( label );
    std::cout << std::setw( 17 ) << filter->GetFalsePositiveError( label );
    std::cout << std::endl;
    }
 
  return EXIT_SUCCESS;
}





int main( int argc, char *argv[] )
{
  if( argc < 4 )
    {
    std::cerr << "Usage: " << argv[0] << " imageDimension sourceImage "
      << "targetImage" << std::endl;
    return EXIT_FAILURE;
    }

  switch( atoi( argv[1] ) )
   {
   case 2:
     LabelOverlapMeasures<2>( argc, argv );
     break;
   case 3:
     LabelOverlapMeasures<3>( argc, argv );
     break;
   default:
      std::cerr << "Unsupported dimension" << std::endl;
      exit( EXIT_FAILURE );
   }
  
}

Here is my code .. :)

Thanks

Edited 5 Years Ago by jowana: n/a

That's not all of your code because it doesn't compile. But I'll assume that your issue was failing to qualify cin with std::

#include <iostream>

// ...

int main( int argc, char *argv[] )
{
    if( argc < 4 )
    {
        std::cerr << "Usage: " << argv[0] << " imageDimension sourceImage "
            << "targetImage" << std::endl;
        return EXIT_FAILURE;
    }

    switch( atoi( argv[1] ) )
    {
    case 2:
        LabelOverlapMeasures<2>( argc, argv );
        break;
    case 3:
        LabelOverlapMeasures<3>( argc, argv );
        break;
    default:
        std::cerr << "Unsupported dimension" << std::endl;
        exit( EXIT_FAILURE );
    }

    std::cin.ignore(1024, '\n');
    std::cin.get();
}

Hi,

yes it did work now ..
the program does compile prefectly with me and the answers are exactly as what im looking for,

Thanks for the help :)

Regards,

Edited 5 Years Ago by jowana: n/a

You can also use system("PAUSE") but I think it is only for windows. Anyway Narue's way is good too, and "terminal" sounds like linux and I don't think system("PAUSE"); works there.

You can also use system("PAUSE") but I think it is only for windows.

system("PAUSE") will work for any system that has a PAUSE program available. This is a very Bad Thing™ because that program doesn't need to be provided by the system, nor does it need to do anything even close to suspending execution of your program. Even on Windows, where this idiom originated and a system-provided PAUSE program is available, a malicious user could replace that program with malware under the same name and you'd run it happily.

The system("PAUSE") idiom is a huge, gaping security hole.

Edited 5 Years Ago by Narue: n/a

Thanks for telling me. You scared with with that hacker stuff :) From now on I will make my own system pause programs functions.

Edited 5 Years Ago by sergent: spelling corrections

You scared with with that hacker stuff

If that scares you, I'll refrain from telling tales of my darker past. Narue wasn't always the glowing beacon of kindness and generosity that you see today. ;)

:) I would like to hear those stories. I actually wanted to be a hacker when I was 11 years old and thats how I started programming. But I find "good" programming much more fun then hacking. But still I do not find current copyright laws suitable for our society so.... errrr, Me is a pirate.

Edited 5 Years Ago by sergent: n/a

This question has already been answered. Start a new discussion instead.