gpt4 book ai didi

c++ - 警告 : unused variable ‘arrPixel’ [-Wunused-variable]

转载 作者:行者123 更新时间:2023-11-28 00:33:43 27 4
gpt4 key购买 nike

main.cpp

#include <iostream>
#include <fstream>
#include "steganography.h" // call steganography class

const int arrSize = 30000;//array for contains pixels
using namespace std;
int main()

{
char FileName[20] = "new.txt";
char NewFile[20] = "new.ppm";
char arrPixel[arrSize] = {};
int count = 0;
int option;
Steganography A;//create the reference of steganopragpy class
cout<<"Choose Enocde/Decode[1/2]"; // take option from user
cin>>option;
switch(option)
{
case 1:
cout << "Enter PPM File Name" << endl;
cin>>FileName;
cout << "Enter Output File Name"<< endl;
cin>>NewFile;
A.readImage(FileName, arrPixel);//call readImage method
cout << "Encoded Successfully completed:" << endl;
A.printImage( NewFile, arrPixel);//write ppm
break;
case 2:
cout << "Enter Input File Name" << endl;
cin>>FileName;
cout << "Enter Output PPM File Name"<< endl;
cin>>NewFile;
A.readCipherText( NewFile, arrPixel);//call read file method
cout << "Decoded Successfully completed:" << endl;
A.printCipherText(FileName, arrPixel);//write ppm
break;

default:
cout<<"wrong choice";
}

// cout << NewFile << endl;
for(int ct = 0; ct > arrSize; ct++)
{
cout << arrPixel[ct];
}


return 0;
}

隐写术.cpp

#include <iostream>
#include <fstream>
#include <string>
#include "steganography.h" // call steganography class
const int arrSize = 30000;//array for contains pixels
using namespace std;

Steganography::Steganography()//call steganography constructor
{

char arrPixel[arrSize] = {};
}


void Steganography::readImage(char* FileName, char* arrPixel)//read image
{
ifstream infile (FileName);//open file
if(infile.is_open())
{
for(int count = 0; count < arrSize; count++)
{
infile >> noskipws >> arrPixel[count];
}
}
else
{
cout << "Error opening new file." << endl;
//abort();
}
infile.close();
}

void Steganography::readCipherText(char* FileName, char* arrPixel)//read text file contains ppm info
{
ifstream infile (FileName);
if(infile.is_open())
{
for(int count = 0; count < arrSize; count++)
{
infile >> noskipws >> arrPixel[count];
}
}
else
{
cout << "Error opening new file." << endl;
//abort();
}
infile.close();
}

void Steganography::printImage(char* NewFile, char* arrPixel)//write image
{

ofstream outfile (NewFile);

if(outfile.is_open())

{

int count = arrSize;
for(int i = 0; i < (count - 1); i++)
{
outfile << arrPixel[i];
}
}
else
{
cout << "Error opening new file." << endl;
// abort();
}
outfile.close();

}
void Steganography::printCipherText(char* NewFile, char* arrPixel)//write ppm file
{

ofstream outfile (NewFile);

if(outfile.is_open())

{

int count = arrSize;
for(int i = 0; i < (count - 1); i++)
{
outfile << arrPixel[i];
}
}
else
{
cout << "Error opening new file." << endl;
// abort();
}
outfile.close();

}

隐写术.h

#ifndef STEGANOGRAPHY_H
#define STEGANOGRAPHY_H
#include <string>
#include <vector>
class Steganography {
private:
// Image header
std::string image_type;
int width, height;
int max_color_depth;
// Image data
std::vector<int> color_data;

// Hidden data
std::string ciphertext;
int getNthBit(char cipher_char, int n);

public:
Steganography(void); //Constructor
void readImage(char*,char*);



void printImage(char*,char*);



void readCipherText(char*,char*);


void printCipherText(char*,char*);


void cleanImage();


void encipher();



void decipher();

};

#endif

当我编译时,我收到这个警告:

steganography.cpp: In constructor ‘Steganography::Steganography()’:
steganography.cpp:11:10: warning: unused variable ‘arrPixel’ [-Wunused-variable]

谁能帮我解决这个问题。另外,我必须写下这一行 const int arrSize = 30000;在 Main.cpp 和 steganography.cpp 中以避免出错,有没有办法只在 steganography.cpp 上写入它而不会出错?

最佳答案

这里:

Steganography::Steganography()//call steganography constructor
{

char arrPixel[arrSize] = {};
}

您声明了一个名为 arrPixel 的局部变量,但您没有使用它。您可以删除该行。

请注意,您收到的是警告,而不是错误。

关于c++ - 警告 : unused variable ‘arrPixel’ [-Wunused-variable],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21770082/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com