我正在尝试从txt文件中读取格式的一些十六进制值。
纯文字= a7f1d92a82c8d8fe Othertext = 76f467db07371675
纯文本= 434d98558ce2b347 Othertext = f1c67a7ee683eca2
然后将这些值输入到计算中。我尝试使用下面的代码,但是有2个问题。首先,我似乎只能以字符串形式输入。其次,我可以很好地弄清楚如何定义将存储它们的数组。我需要可以将它们放入类似内容的东西:
char Plaintextarray [8] [3] = {“ a7”,“ f1”,“ d9”,“ 2a”,“ 82”,“ c8”,“ d8”,“ fe”};
谢谢,利亚姆。
void ReadTextPairs()
{
string array[700]; // creates array to hold names
string Parray[700];
string Carray[700];
string line; //this will contain the data read from the file
short loop = 0; //short for loop for input
int i = 0,j = 0;
ifstream myfile("C:\\textfile.txt"); //opening the file.
if (myfile.is_open()) //if the file is open
{
while (!myfile.eof()) //while the end of file is NOT reached
{
getline(myfile,line); //get one line from the file
if (line.find("Plaintext=") != string::npos) { Parray[i] = line.substr(12); i++; }
if (line.find("Othertext=") != string::npos) { Carray[j] = line.substr(12); j++; }
array[loop] = line;
loop++;
}
myfile.close(); //closing the file
for (int k = 0; k < (i - 1); k++) {
cout << Parray[k] << "\t" << Carray[k] << "\n";
}
}
else cout << "Unable to open file"; //if the file is not open output
printf("\nNumber of key pairs read %d\n",i);
//return ();
}