Question: Code Below is in C++. Please give some vulnerabilities present in the code given below. Also, if you could give some that include string manipulation

Code Below is in C++.

Please give some vulnerabilities present in the code given below. Also, if you could give some that include string manipulation errors, that would be greatly appreciated. Thanks.

#include

#include

#include

#include

using namespace std;

void stringReverse(string & str) {

int n = str.length();

for(int i = 0; i < n / 2; i++)

swap(str[i], str[n - i - 1]);

}

int main() {

.

ofstream outfile;

string data;.

cout << "Please enter a string" << endl;

getline(cin, data);

outfile.open("CSC450_CT5_mod5.txt", std::ios_base::app);

outfile << data << endl;

ofstream outfile2("CSC450_CT5_mod5_reversed.txt");

ifstream infile("CSC450_CT5_mod5.txt");

while(infile) {

getline(infile, data);

stringReverse(data);

outfile2 << data << endl;

}

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!