/*****************************************************************//** * \file ConsoleTextFileDemoApp.cpp c++ 14 * \brief * * * \author geovindu * \date June 2023 *********************************************************************/ // ConsoleTextFileDemoApp.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 //https://stackoverflow.com/questions/936687/how-do-i-declare-a-2d-array-in-c-using-new //geovindu Geovin Du #define _UNICODE #define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <windows.h> #include <string> #include <string.h> #include <fstream> #include <stdio.h> #include <cstdlib> #include <cstring> #include <iomanip> #include <cstdio> #include <codecvt> #include <assert.h> #include <windows.h> #include <iostream> #include <fstream> #include <io.h> #include <vector> using namespace std; /// <summary> /// 打印二维数组 /// </summary> /// <param name="p"></param> /// <param name="rowNum">行</param> /// <param name="coluNum">列</param> void PrintPtr(int** p, int rowNum, int coluNumn) { for (int i = 0; i < rowNum; i++) { for (int j = 0; j < coluNumn; j++) cout << p[i][j] << " "; cout << endl; } } /// <summary> /// /// </summary> /// <param name="arry"></param> /// <param name="row"></param> void PrintAr2(int arry[][9], int row) { for (int i = 0; i < row; i++) { for (int j = 0; j < 9; j++) cout << arry[i][j] << " "; cout << endl; } } /// <summary> /// 打印二维数组 /// </summary> /// <param name="p"></param> /// <param name="rowNum"></param> /// <param name="coluNum"></param> void print_p(int** p, int rowNum, int coluNum) { cout << "\n------------------------" << endl; for (int i = 0; i < rowNum; i++) { for (int j = 0; j < coluNum; j++) { cout << p[i][j] << " "; } cout << endl; } } /// <summary> /// /// </summary> /// <param name="p"></param> /// <param name="RowSize"></param> /// <param name="LineSize"></param> void print_array(int* p, int RowSize, int LineSize) { int i, j; for (i = 0; i < RowSize; i++) { for (j = 0; j < LineSize; j++) printf("%d ", *(p + i * LineSize + j)); printf("\n"); } } /// <summary> /// 初始化二维数组,即给指针p分配内存。这里注意要使用引用 /// </summary> /// <param name="p"></param> /// <param name="rowNum"></param> /// <param name="coluNum"></param> void init_p(int**& p, int* rowNum, int* coluNum) { cin >> *rowNum >> *coluNum; p = new int* [*rowNum]; for (int i = 0; i < *rowNum; i++) { p[i] = new int[*coluNum]; } } int main(void) { std::cout << "Hello World! 涂聚文! \n"; //string duname; //cout << "输入姓名:" << endl; //cin >> duname; //cout << "name:" << duname << endl; int sudoku[9][9] = { {0, 0, 0, 0, 0, 9, 0, 5, 0}, {0, 0, 8, 0, 0, 0, 0, 7, 9}, {0, 0, 1, 5, 0, 2, 0, 0, 0}, {3, 0, 0, 0, 1, 0, 5, 0, 7}, {2, 0, 4, 0, 0, 7, 0, 0, 0}, {0, 0, 0, 6, 0, 0, 2, 0, 0}, {0, 0, 0, 0, 7, 0, 3, 4, 0}, {1, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 3, 0, 0, 5, 6, 0, 0, 0} }; int** p = new int* [9]; for (int i = 0; i < 9; i++) p[i] = new int[10]; for (int i = 0; i < 9; i++) { for (int j = 0; j < 9; j++) p[i][j] = sudoku[i][j]; } cout << "传递数组名" << endl; PrintAr2(sudoku, 9); cout << "传递指针" << endl; PrintPtr(p, 9, 9); int i, j; print_array((int*)sudoku, 9, 9); cout << "***********" << endl; for (i = 0; i <9; i++) { for (j = 0; j < 9; j++) printf("%d ", *(*(sudoku + i) + j)); printf("\n"); } wstring allstr; wstring sname; wstring stuID;//学号 int num;//编号 double english;//英语成绩 double math;//数学成绩 double cpp;//C++成绩 int location = 0;//位置编号 int flag = 0;//标记是否有对应的编号 wcout << L"请输入新增学生的信息" << endl; wcout << L"姓名\t" << "学号\t" << "英语\t" << "数学\t" << "C++\t" << endl; wcin.imbue(locale("chs"));//获取的是中文 wcout.imbue(locale("chs")); wcin >> sname >> stuID >> english >> math >> cpp; //allstr = sname + ' ' + stuID; allstr.append(sname); //C++ wstring::append allstr.append(L"\t"); allstr.append(stuID); allstr.append(L"\t"); allstr.append(to_wstring(english)); allstr.append(L"\t"); allstr.append(to_wstring(math)); allstr.append(L"\t"); allstr.append(to_wstring(cpp)); wcout << allstr << endl; system("pause"); return 0; } // 运行程序: Ctrl + F5 或调试 >“开始执行(不调试)”菜单 // 调试程序: F5 或调试 >“开始调试”菜单 // 入门使用技巧: // 1. 使用解决方案资源管理器窗口添加/管理文件 // 2. 使用团队资源管理器窗口连接到源代码管理 // 3. 使用输出窗口查看生成输出和其他消息 // 4. 使用错误列表窗口查看错误 // 5. 转到“项目”>“添加新项”以创建新的代码文件,或转到“项目”>“添加现有项”以将现有代码文件添加到项目 // 6. 将来,若要再次打开此项目,请转到“文件”>“打开”>“项目”并选择 .sln 文件 #define UNICODE
标签:level,int,double,Two,++,allstr,rowNum,include,append From: https://www.cnblogs.com/geovindu/p/17517844.html