Osiris-Testseite

Aus Physik
Zur Navigation springen Zur Suche springen

C - C++ Vergleich

C-Version:

   char point_style[GP_CMD_SIZE];
   char * token_pointer = strchr(plot_style, ' ');
   int style_str_len;
   if (token_pointer != NULL)
   {
       style_str_len = token_pointer - plot_style;
   }
   else
   {
       style_str_len = strlen(plot_style);
   }
   strncpy(point_style, plot_style, style_str_len);
   point_style[style_str_len] = 0;

   if (strcmp(point_style, "lines") &&
       strcmp(point_style, "points") &&
       strcmp(point_style, "linespoints") &&
       strcmp(point_style, "impulses") &&
       strcmp(point_style, "dots") &&
       strcmp(point_style, "steps") &&
       strcmp(point_style, "errorbars") &&
       strcmp(point_style, "boxes") &&
       strcmp(point_style, "boxerrorbars")) 
   {
           fprintf(stderr, "warning: unknown requested style: using points\n") ;
           strcpy(h->pstyle, "points") ;
   } else {
       strcpy(h->pstyle, plot_style) ;
   }

C++ Version

   string linestylestr = stylestr.substr(0, stylestr.find(" "));

   if (linestylestr != "lines" &&
       linestylestr != "points" &&
       linestylestr != "linespoints" &&
       linestylestr != "impulses" &&
       linestylestr != "dots" &&
       linestylestr != "steps" &&
       linestylestr != "errorbars" &&
       linestylestr != "boxes" &&
       linestylestr != "boxerrorbars")
       this->pstyle = string("points");
   else
       this->pstyle = stylestr;