11/08/2011 00:14 by ThomasOakes
Declare a sting to reverse. Enter the following into the text editor:
#include
#include
#include
using namespace std;
int main(){
string line1, line2;
ifstream file ("filename.txt");
if (file.good())
{
getline(file, line1);
}
file.close();
}
The goal, then, is to take "line1" (which contains a line from the file "filename.txt") and reverse it.
Create a loop to iterate over the string, in reverse. Enter the following into the text editor:
int i = (int)line1.length() -1;
for (i; i >= 0; i--)
{
line2 += line1[i]
}
The "for" loop starts with "i" referring to the position of the last character in the sentence. It appends that letter to line2, and moves to the next character of line1 in reverse.
Print out the reverse line. Enter the following into the text editor, following the loop:
cout
A:Because file extensions are chosen based on the preferences of programmers during software development, it is possible for unrelated files to ...(more)
A:Music production software is used to edit songs and then save the resulting music as a digital file. There are a number of music production so...(more)
A:Because file extensions are selected by programmers based upon their own preferences, it is possible for unrelated types of files to share a c...(more)
A: Download, install and run the ZaZ Tools software suite. Double-click on the SlimTex application. Click on the "Batch to TGA" tab at the ...(more)
A:Convert the DVF File to WAV Format Right-click on the DVF file to show the Windows context menu. Click the "Open With" option. A list of a...(more)
Added Successfully!
×Voted Successfully!
×You can't vote for yourself
×You can't choose your own answer
×