C++

2D array

TGraph*** g = new TGraph**[Nfile];
for(i loop) g[i] = new TGraph*[t[i]->Nentries];
for(int j = 0; j<t[i]->Nentries;j++) g[i][j] = ...(TGraph *)...

EOF

<<EOF        //开始
....
EOF            //结束

//将一个文件的内容输出到另一个文件中:
# cat fileA > fileB
//将"<< EOF EOF"替代输入对象文件fileA:
# cat << EOF > fileB
//命令执行后,提示用户输入内容,输入结束后,用户的输入内容被保存到了fileB中。

I/O

    #include <fiostream.h>
    int main () {
        ofstream out("out.txt");
        if (out.is_open()) 
       {
            out << "This is a line.\n";
            out.close();
        }
      return 0;
      
 // reading a text file
    #include <iostream.h>
    #include <fstream.h>
    #include <stdlib.h>
    
    int main () {
        char buffer[256];
        ifstream in("test.txt");
        if (! in.is_open())
        { cout << "Error opening file"; exit (1); }
        while (!in.eof() )
        {
            in.getline (buffer,100);
            cout << buffer << endl;
        }
        return 0;
std::vector<char> v;

	if (FILE *fp = fopen("filename", "r"))
	{
		char buf[1024];
		while (size_t len = fread(buf, 1, sizeof(buf), fp))
			v.insert(v.end(), buf, buf + len);
		fclose(fp);
	}

将变量名替换为字符串

#define name2str(name) (#name)
    
#define xstr(s) str(s)
#define str(s) #s
#define foo 4

     str (foo)
          ==> "foo"
     xstr (foo)
          ==> xstr (4)
          ==> str (4)
          ==> "4"
 

函数指针作为参数

void DiffusionModel (bool (*GeometryFunction)(double, double, double)) )
bool InsideAerogel(double x, double y, double z);
		
DiffusionModel(
    InsideAerogel
);

char * 转换 (for input arg.)

//char* to int

int a = stoi(argv[1]);
 
//char* 转 float/double
float b = stof(argv[2]);
double bb = stod(argv[2]);
 
//char* 转 string (可以直接转)
string str = argv[3];
cout << a << endl << b << endl << bb << endl << str << endl;