Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
soft:c [2020/07/24 08:23] – Ce Zhang | soft:c [2020/11/05 02:10] (current) – Ce Zhang | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====C++==== | + | =====C++===== |
- | ===Read=== | + | |
- | '' | + | ==== 2D array ==== |
+ | < | ||
+ | TGraph*** g = new TGraph**[Nfile]; | ||
+ | for(i loop) g[i] = new TGraph*[t[i]-> | ||
+ | for(int j = 0; j< | ||
+ | </ | ||
- | #include | + | ====EOF==== |
- | * ofstream | + | < |
- | * ifstream | + | <<EOF // |
- | * fstream | + | .... |
+ | EOF // | ||
+ | |||
+ | // | ||
+ | # cat fileA > fileB | ||
+ | //将"<< EOF EOF" | ||
+ | # cat << EOF > fileB | ||
+ | // | ||
+ | </ | ||
+ | |||
+ | ====I/O==== | ||
< | < | ||
Line 19: | Line 33: | ||
} | } | ||
return 0; | return 0; | ||
+ | | ||
+ | // reading a text file | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | | ||
+ | int main () { | ||
+ | char buffer[256]; | ||
+ | ifstream in(" | ||
+ | if (! in.is_open()) | ||
+ | { cout << "Error opening file"; exit (1); } | ||
+ | while (!in.eof() ) | ||
+ | { | ||
+ | in.getline (buffer, | ||
+ | cout << buffer << endl; | ||
+ | } | ||
+ | return 0; | ||
</ | </ | ||
+ | |||
+ | < | ||
+ | std:: | ||
+ | |||
+ | if (FILE *fp = fopen(" | ||
+ | { | ||
+ | char buf[1024]; | ||
+ | while (size_t len = fread(buf, 1, sizeof(buf), | ||
+ | v.insert(v.end(), | ||
+ | fclose(fp); | ||
+ | } | ||
+ | </ | ||
+ | ====将变量名替换为字符串==== | ||
+ | < | ||
+ | #define name2str(name) (#name) | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | #define xstr(s) str(s) | ||
+ | #define str(s) #s | ||
+ | #define foo 4 | ||
+ | |||
+ | str (foo) | ||
+ | ==> " | ||
+ | xstr (foo) | ||
+ | ==> xstr (4) | ||
+ | ==> str (4) | ||
+ | ==> " | ||
+ | </ | ||
+ | |||
+ | ====函数指针作为参数==== | ||
+ | < | ||
+ | |||
+ | void DiffusionModel (bool (*GeometryFunction)(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/ | ||
+ | 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; | ||
+ | </ |