我写这个是为了生成一个随机密码:
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
using namespace std;
string read(string value) { //read value
ifstream input;
int olength;
string line = "", output = "";
size_t pos;
bool a = true;
int i = 0;
input.open("pg_options.txt");
if (!input.is_open()) {
cout << "pg_options.txt missing.";
return "error";
}
while (getline(input, line)) {
pos = line.find(value);
if (pos != string::npos) {
while (a == true) {
if (line[i] == '=') {
i++;
break;
}
else {
i++;
}
} …Run Code Online (Sandbox Code Playgroud)