Quantcast
Channel: Visual C forum
Viewing all articles
Browse latest Browse all 15302

cout problem

$
0
0

hi,all, I am using GAlib and encountered a cout problem. The example program uses 'cout' to display msg in a console:

#define cout STD_COUT
#define endl STD_ENDL

cout << "the ga generated:\n" << ga4.statistics().bestIndividual() << endl;

I am using GAlib in my MFC project, so I wonder is there a way to put the content of the 'cout' msg in a cstring in MFC or to use OutputDebugString(LPCTSTR szMessage), but I am not familiar with C, so I wonder how to do that. the following is how GAlib print msg is defined in its source package:

const GAGenome & 
GAStatistics::bestIndividual(unsigned int n) const {
  if(boa == 0 || (int)n >= boa->size()){
    GAErr(GA_LOC, "GAStatistics", "bestIndividual", gaErrBadPopIndex);
    n = 0;
  }
  return boa->best(n);		// this will crash if no boa
}

void 
GAErr(const GASourceLocator loc, const char *clss, const char *func,
      GAErrorIndex i, const char *msg2, const char *msg3){
  gaErrMsg[0] = '\0';
  strcat(gaErrMsg, clss);
  strcat(gaErrMsg, "::");
  strcat(gaErrMsg, func);
  strcat(gaErrMsg, ":\n  ");
  strcat(gaErrMsg, __gaErrStr[i]);
  strcat(gaErrMsg, "\n");
  if(msg2){
    strcat(gaErrMsg, "  ");
    strcat(gaErrMsg, msg2);
    strcat(gaErrMsg, "\n");
  }
  if(msg3){
    strcat(gaErrMsg, "  ");
    strcat(gaErrMsg, msg3);
    strcat(gaErrMsg, "\n");
  }
  sprintf(_gaerrbuf1, "  %s : %ld\n", loc.file, loc.line);
  strcat(gaErrMsg, _gaerrbuf1);
#ifdef GALIB_USE_STREAMS
  if(__gaErrFlag == gaTrue) *__gaErrStream << gaErrMsg;
#endif
}

GAGenome& best(unsigned int i=0, SortBasis basis=RAW) const {
    if(basis == SCALED) scale();
    sort(gaFalse, basis);
    return ((basis == RAW) ? *(rind[i]) : *(sind[i])); 
  }



Viewing all articles
Browse latest Browse all 15302

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>