为什么我的代码不写入 C++ 中的文件?
我编写了一个获取输入数据的代码,将其写入字符串,然后将其发送到加密的临时文件,然后临时将加密的文件发送到主文件。我设法以某种方式使它起作用(只有寄存器),但我没有对代码做任何事情,现在数据没有写在文件上。任何类型的帮助都将受到欢迎。谢谢!
#include<iostream>
#include<istream>
#include<fstream>
#include<stdlib.h>
#include<string.h>
#include<stdio.h>
using namespace std;
void login();
void reg();
void encrypt();
int main() {
int rep;
cout << "\t\t\t Welcome to Protek 0.1.\n" << "\t\t\t Do you already have a account?\n\n";
cout << "\t\t\t\t 1 = YES 2 = NO\n";
cin >> rep;
switch (rep) {
case 1:
login();
break;
case 2:
reg();
break;
default:
break;
}
}
void login() {
int count;
string LUserN, LUserP, LN, LP;
system("cls");
cout << "Please enter your name.";
cin >> LUserN;
cout << "Please enter your pass.";
cin >> LUserP;
ifstream input("data/pn.txt");
while (input>>LN>>LP) {
if (LN==LUserN && LP==LUserP) {
count = 1;
}
}
input.close();
if (count == 1) {
cout << "\t\t\t SUCCESS! \n";
cin.get();
cin.get();
main();
}
else {
cout << "\t\t\t ERROR";
main();
}
}
void reg() {
string RUserN, RUserP;
system("cls");
cout << "\t\t\t Enter your username. \n";
cin >> RUserN;
cout << "\t\t\t Enter pass. \n";
cin >> RUserP;
encrypt();
cout<< "\t\t\t Reg Complete!\n";
main();
}
void encrypt() {
char ch;
fstream fps, fpt;
fps.open("data/pn.txt", fstream::in);
fpt.open("data/pt.txt", fstream::out);
while (fps >> ch) {
ch = ch * 22;
fpt << ch;
}
fps.close();
fpt.close();
fps.open("data/pn.txt", fstream::out);
fpt.open("data/pt.txt", fstream::in);
while (fpt >> ch)
fps << ch;
fpt.close();
fps.close();
}
I wrote a code that takes input data, writes it on a string then it is sent to a temp file that gets encrypted and the temp sends the encrypted file to the main file. Somehow I managed to make it work (only the register) but I didn't do anything to the code and now the data isn't written on the files. Any kind of help will be welcomed. Thanks!
#include<iostream>
#include<istream>
#include<fstream>
#include<stdlib.h>
#include<string.h>
#include<stdio.h>
using namespace std;
void login();
void reg();
void encrypt();
int main() {
int rep;
cout << "\t\t\t Welcome to Protek 0.1.\n" << "\t\t\t Do you already have a account?\n\n";
cout << "\t\t\t\t 1 = YES 2 = NO\n";
cin >> rep;
switch (rep) {
case 1:
login();
break;
case 2:
reg();
break;
default:
break;
}
}
void login() {
int count;
string LUserN, LUserP, LN, LP;
system("cls");
cout << "Please enter your name.";
cin >> LUserN;
cout << "Please enter your pass.";
cin >> LUserP;
ifstream input("data/pn.txt");
while (input>>LN>>LP) {
if (LN==LUserN && LP==LUserP) {
count = 1;
}
}
input.close();
if (count == 1) {
cout << "\t\t\t SUCCESS! \n";
cin.get();
cin.get();
main();
}
else {
cout << "\t\t\t ERROR";
main();
}
}
void reg() {
string RUserN, RUserP;
system("cls");
cout << "\t\t\t Enter your username. \n";
cin >> RUserN;
cout << "\t\t\t Enter pass. \n";
cin >> RUserP;
encrypt();
cout<< "\t\t\t Reg Complete!\n";
main();
}
void encrypt() {
char ch;
fstream fps, fpt;
fps.open("data/pn.txt", fstream::in);
fpt.open("data/pt.txt", fstream::out);
while (fps >> ch) {
ch = ch * 22;
fpt << ch;
}
fps.close();
fpt.close();
fps.open("data/pn.txt", fstream::out);
fpt.open("data/pt.txt", fstream::in);
while (fpt >> ch)
fps << ch;
fpt.close();
fps.close();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论