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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started