C ++ - Warnung: veraltete Konvertierung von String-Konstante in 'char *' [-Write-Strings]
Ich bin mit gnuplot ein Diagramm zeichnen in C++. Der graph wird plot als erwartet, aber es ist auch eine Warnung beim kompilieren. Was bedeutet die Warnung?
warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
Dies ist die Funktion die ich benutze:
void plotgraph(double xvals[],double yvals[], int NUM_POINTS)
{
char * commandsForGnuplot[] = {"set title \"Probability Graph\"",
"plot 'data.temp' with lines"};
FILE * temp = fopen("data.temp", "w");
FILE * gnuplotPipe = popen ("gnuplot -persistent ", "w");
int i;
for (i=0; i < NUM_POINTS; i++)
{
fprintf(temp, "%lf %lf \n", xvals[i], yvals[i]);
//Write the data to a te mporary file
}
for (i=0; i < NUM_COMMANDS; i++)
{
fprintf(gnuplotPipe, "%s \n", commandsForGnuplot[i]);
//Send commands to gn uplot one by one.
}
fflush(gnuplotPipe);
}
InformationsquelleAutor der Frage Sagar | 2014-02-03
Du musst angemeldet sein, um einen Kommentar abzugeben.
String-Literale sind eine array von const char sehen wir dies aus dem Entwurf der C++ - standard Abschnitt
2.14.5
String-Literaledie sagt (Hervorhebung von mir):also diese änderung wird das entfernen der Warnung:
Hinweis, so dass ein *nicht-const char** Punkt-zu - const Daten ist eine schlechte Idee, da die änderung einer const oder eine string-literal ist Undefiniertes Verhalten. Wir können dies sehen, gehen Sie zu Abschnitt
7.1.6.1
Die cv-Qualifierdie sagt:und Abschnitt
2.14.5
String-Literaledie sagt:InformationsquelleAutor der Antwort Shafik Yaghmour