Well, I've been working on this for the past 2 hours, with little to gain... I am supposed to take a string and reverse it with no loops. in this assignment, we are using fstream functions. This is what I've 'evolved to' this does not work whatsoever, but I am showing I've tried to do some work. I very well may have the wrong concept with some of these fstream functions, and I welcome any extra knowledge on the subject that seems unclear. while I've done quite a bit of internet research(I have googled it - lots of parts of it too) I would like pointers, and perhaps sample code(that doesn't actually solve my problem but shows me how these operators work) Thanks in advance for any help. Going to get some rest so I can finish my program in the morning.
int complexReverseString()
{
string reverse;
ofstream output("information.txt", ios::ate);//open the file for output backwards
int sizeOfString = sizeof("information.txt"); //find the size of string, thought I might need it
advance("information.txt", 1); //while I know this doesn't work, it's kind of the track I'm thinking about...
cout >> reverse;//I know this doesn't do anything, however I will have to cout at some point
return reverse;
}
I would think the only way to do this without an explicit or implicit (via a call to the standard library) loop would be recursion. I don't see that fstreams have anything to do with the problem.
This would better be reserved for a "beginners" question, but why do some programmers use the std:: commands in front of most things? I understand it's calling the standard library, but isn't it easier to call using namespace std;? So far(and I really am kind of a beginner, so I was seriously asking) my class has never used the "std::" command. If I were to use the namespace std and still use this as an example, would it look like:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include <iostream>
#include <string>
using mainspace std;
int main()
{
string source( "Hello eyesofhope" );
cout << "The original string is " << source << endl;
string target( source.rbegin(), source.rend() );
cout << "The reversed string is " << target << endl;
return 0;
}