Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C++;字符串/文件_C++_String_File - Fatal编程技术网

C++ C++;字符串/文件

C++ C++;字符串/文件,c++,string,file,C++,String,File,我试图读取一个包含SSN、用户名和密码列表的文件。我正在尝试用x来替换除最后4个之外的所有社交网站,我有一个系统,根据密码的强度给出积分(“此部分使用累加器”)。我在用cout从main输出表格时遇到问题,希望得到一些帮助。当我尝试从main输出它时,它只执行文件的最后一行,而该行上的SSN不是我想要的x。谢谢 #include <iostream> #include <fstream> #include <iomanip> #include <stri

我试图读取一个包含SSN、用户名和密码列表的文件。我正在尝试用x来替换除最后4个之外的所有社交网站,我有一个系统,根据密码的强度给出积分(“此部分使用累加器”)。我在用cout从main输出表格时遇到问题,希望得到一些帮助。当我尝试从main输出它时,它只执行文件的最后一行,而该行上的SSN不是我想要的x。谢谢

#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;

void openFile(ifstream&, string, string, string);
string xReplace(ifstream& myIn, string& social, string& username, string&     password, string socialRep);
void passStrength(int& count1, int& count2, int& count3, int& accumulator,   ifstream& myIn, string& social, string& username, string& password);


int main()
{
ifstream myIn;
string path, file;
string fileName;
string social;
string username;
string password;
string socialRep = "xxx-xx";
string oneLine = social + username + password;
int count1 = 0;
int count2 = 0;
int count3 = 0;
int accumulator = 0;

openFile(myIn, path, file, fileName);
xReplace(myIn, social, username, password, socialRep);
passStrength(count1, count2, count3, accumulator, myIn, social, username, password);


myIn >> social >> username >> password >> accumulator;
while (myIn.good())

cout << "SSN\tUser Name\tPassword\tPassword Strength\n";
cout << "---------------------------------------------------------\n";
cout << social << " " << username << " " << password << " " << accumulator << "\n";


return 0;
}


void openFile(ifstream& myIn, string path, string file, string fileName)
{

path = "C:\\2430";
cout << "Enter the name of your file";
getline(cin, file);

fileName = path + "\\" + file;
cout << "The file name is " << fileName << endl;

myIn.open(fileName.c_str());
if (myIn.fail())
{
cout << "Filename was invalid\n";
exit(1);
}
cout << "The file" " " << file << "has been opened\n";

}


void passStrength(int& count1, int& count2, int& count3, int& accumulator, ifstream& myIn, string& social, string& username, string& password)
{

while (myIn >> social >> username >> password)
{
for (unsigned int i = 0; i > password.length(); i++)
if (password.length() > 8)

count1 = 1;

else count1 = 0;

int testing = -1;
testing = password.find_first_of("ABCDEFGHIJKLMNOPQRSTUVWXYZ");

if (testing != password.npos)

count2 = 1;

else count2 = 0;

unsigned int testing2 = -1;
testing2 = password.find_first_of("!@#$%^&*()");
if (testing2 != password.npos)

count3 = 1;

else count3 = 0;

accumulator = count1 + count2 + count3;
//cout << social << " " << username << " " << password << " " <<accumulator<< "\n";


}
}

string xReplace(ifstream& myIn, string& social, string& username, string&    password, string socialRep)
{

myIn >> social >> username >> password;
social.replace(0, 6, socialRep);
return social;
}
#包括
#包括
#包括
#包括
使用名称空间std;
void openFile(ifstream&,string,string,string);
字符串xReplace(ifstream&myIn、字符串&social、字符串&username、字符串&password、字符串socialRep);
无效密码强度(int&count1、int&count2、int&count3、int&acculator、ifstream&myIn、string&social、string&username、string&password);
int main()
{
ifmyin;
字符串路径,文件;
字符串文件名;
弦社会;
字符串用户名;
字符串密码;
字符串socialRep=“xxx xx”;
字符串oneLine=社交+用户名+密码;
int count1=0;
int count2=0;
int count3=0;
int累加器=0;
openFile(myIn、路径、文件、文件名);
xReplace(myIn、social、用户名、密码、socialRep);
passStrength(count1、count2、count3、累加器、myIn、社交、用户名、密码);
myIn>>社交>>用户名>>密码>>累加器;
while(myIn.good())

您需要一个容器来保存程序中的记录。变量一次只能保存一个数据

您可以为以下变量定义结构记录:社会变量、用户名和密码,如下所示:

struct record{
   string social;
   string username;
   string password;
};
并创建一个std::vector,如下所示

std::vector<record> my_records;
处理
my_records
中的记录,最后打印
my_records
中的数据

my_reccords.push_back(recod_data);