C++ table example
#include
using namespace std; int main() { int y,x; for (y=2; y<13; y++) { for (x=1; x<13; x++) { cout<
Student Mark
#include
using namespace std; struct student { char name[50]; int roll; float marks; } s[10]; int main() { cout << "Enter information of students: " << endl; // storing information for(int i = 0; i < 10; ++i) { s[i].roll = i+1; cout << "For roll number" << s[i].roll << "," << endl; cout << "Enter name: "; cin >> s[i].name; cout << "Enter marks: "; cin >> s[i].marks; cout << endl; } cout << "Displaying Information: " << endl; // Displaying information for(int i = 0; i < 10; ++i) { cout << "\nRoll number: " << i+1 << endl; cout << "Name: " << s[i].name << endl; cout << "Marks: " << s[i].marks << endl; } return 0; }
Display log file
#include
#include
#include
void displayLogFile(const std::string& filePath) { std::ifstream logFile(filePath); if (logFile.is_open()) { std::string line; std::cout << "Log File Content:" << std::endl; while (std::getline(logFile, line)) { std::cout << line << std::endl; } logFile.close(); } else { std::cerr << "Error opening log file" << std::endl; } } int main() { // Change the file path to your log file std::string logFilePath = "connection_log.txt"; displayLogFile(logFilePath); return 0; }
Switch to root user
#include
#include
int main() { // Switch to the root user if (setuid(0) == 0) { std::cout << "Switched to the root user" << std::endl; // Now you can perform actions as the root user // ... // It's advisable to drop privileges after performing necessary actions // For example, revert to the original user: if (setuid(getuid()) == 0) { std::cout << "Reverted to the original user" << std::endl; } else { perror("Error reverting to the original user"); } } else { perror("Error switching to the root user"); } return 0; }