Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.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
Arrays 希望从txt文件中读取十六进制值_Arrays_Hex - Fatal编程技术网

Arrays 希望从txt文件中读取十六进制值

Arrays 希望从txt文件中读取十六进制值,arrays,hex,Arrays,Hex,我正在尝试从txt文件中读取一些十六进制值 纯文本=a7f1d92a82c8d8fe Othertext=76f467db07371675 纯文本=434d98558ce2b347 其他文本=f1c67a7ee683eca2 然后将这些值输入到计算中。我尝试过使用下面的代码,但有两个问题。首先,我似乎只能把它当作一根绳子来喂。其次,我可以很好地找出如何定义存储它们的数组。我需要一些东西,可以把他们放在像: char Plaintextarray[8][3]={a7”、“f1”、“d9”、“2a”

我正在尝试从txt文件中读取一些十六进制值

纯文本=a7f1d92a82c8d8fe Othertext=76f467db07371675

纯文本=434d98558ce2b347 其他文本=f1c67a7ee683eca2

然后将这些值输入到计算中。我尝试过使用下面的代码,但有两个问题。首先,我似乎只能把它当作一根绳子来喂。其次,我可以很好地找出如何定义存储它们的数组。我需要一些东西,可以把他们放在像:

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 ();
  }
void ReadTextPairs()
{
字符串数组[700];//创建用于保存名称的数组
弦帕雷[700];
串卡雷[700];
字符串行;//这将包含从文件中读取的数据
short-loop=0;//输入循环的缩写
int i=0,j=0;
ifstream myfile(“C:\\textfile.txt”);//打开文件。
if(myfile.is_open())//如果文件已打开
{
while(!myfile.eof())//未到达文件末尾时
{
getline(myfile,line);//从文件中获取一行
if(line.find(“Plaintext=”)!=string::npos){Parray[i]=line.substr(12);i++;}
如果(line.find(“Othertext=”)!=string::npos){Carray[j]=line.substr(12);j++;}
数组[循环]=行;
loop++;
}
myfile.close();//关闭文件
对于(int k=0;k<(i-1);k++){

在读了很多遍你的问题之后,我仍然不明白你的问题是什么。你说“我似乎只能把它作为一个字符串输入”,但你没有解释你想做什么。然后你说“我需要一些东西,比如:char-Plaintextarray[8][3]={…};”但是为什么是8和3?为什么是2维?还有其他文本呢?简言之,如果你想要一个相关的答案,你需要做的是:你需要提供一个输入文件的样本,然后提供你当前通过这个样本获得的输出,并提供你希望通过这个样本作为输入的预期输出。你能吗?好的,我现在明白了在Plaintextarray[8][3]示例中,您想要的是Plaintextarray[8][3],而不是您当前拥有的Parray[8]和Carray[3],对吗?但仍然提供输入/当前输出/所需输出请执行以下操作:我的输入是一个文本文件,其中包含格式为:Plaintext=a7f1d92a82c8d8fe Othertext=76f467db07371675 Plaintext=434d98558ce2b347 Othertext=f1c67a7ee683eca2的连续信息列表。我需要额外添加的项ct是'a7f1d92a82c8d8fe'。这是一个32位的十六进制键。我需要将这些键提取到一个数组中。手动输入名为Plaintextarray的明文数组的格式为:char Plaintextarray[8][3]={“a7”、“f1”、“d9”、“2a”、“82”、“c8”、“d8”、“fe”};如何将文本文件中的键提取到与明文arr格式相同的数组中