我试图从输出中获取单词并找到任何带有字母Q的单词.如果单词确实如此,则需要将其替换为"bad".之后,我试图将每个单词追加到output2.我这样做有困难.我编译时得到的错误是:
从'const char*'到'char'的无效转换[-fpermissive]
#include <iostream>
#include <string>
#include <cstdlib>
#include <sstream>
using namespace std;
string manipulate(string x);
int main(int argc, char* argv[])
{
string input, temp, output, output2, test, test2;
int b;
cout << "Enter a string: ";
getline(cin, input);
istringstream iss(input);
while (iss >> test)
{
if(test.length() != 3)
{
test.append(" ", 1);
output.append(test);
}
}
istringstream iss2(output);
while (iss2 >> test2)
{
for(int i = 0; i<test2.length(); i++)
{
switch(test2[i])
{
case 'q':
test2[1]="bad";
output2.append(test2);
break;
}
} …Run Code Online (Sandbox Code Playgroud) 我试图逐字节复制exe文件.我比较了2的hex文件,它们是完全不同的.似乎有些值没有被加载..
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
int main(){
ifstream fin("file.exe", ifstream::binary);
vector<char> buffer(1, 0);
ofstream newfile;
newfile.open("newfile.exe", ios::binary);
while (fin.read(buffer.data(), buffer.size())){
streamsize s = fin.gcount();
for (int i = 0; i < buffer.size(); i++){
if (buffer[i] != EOF){
newfile << buffer[i];
cout << buffer[i] << endl;
} else {
break;
}
}
}
}
Run Code Online (Sandbox Code Playgroud)