我找到了一个不起眼的日志记录错误,事实上长度为2的初始化列表似乎是一个特例!这怎么可能?
代码是使用Apple LLVM版本5.1(clang-503.0.40)编译的CXXFLAGS=-std=c++11 -stdlib=libc++
.
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
typedef vector<string> Strings;
void print(string const& s) {
printf(s.c_str());
printf("\n");
}
void print(Strings const& ss, string const& name) {
print("Test " + name);
print("Number of strings: " + to_string(ss.size()));
for (auto& s: ss) {
auto t = "length = " + to_string(s.size()) + ": " + s;
print(t);
}
print("\n");
}
void test() {
Strings a{{"hello"}}; print(a, "a");
Strings b{{"hello", "there"}}; print(b, "b");
Strings c{{"hello", …
Run Code Online (Sandbox Code Playgroud) 我正在使用gnuplot在C++中绘制图形.该图正如预期的那样绘制,但在编译期间会出现警告.警告意味着什么?
warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
Run Code Online (Sandbox Code Playgroud)
这是我正在使用的功能:
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]); …
Run Code Online (Sandbox Code Playgroud)