|
-
June 1st, 2012, 11:39 AM
#13
Re: Algorithm problem
 Originally Posted by smurf12125
I need a break function to end the loop of inputting my text not for std::sort and Albert was talking about how I was sorting it as a vecor of ints instead of a vector of strings. I asked since I was using StringArray that I would need to have them input as as int's instead of strings. Here is my code now so you can see what I mean.
Code:
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <vector>
using namespace std;
typedef std::vector <std::string> StringArray;
int main()
{
cout << "This program is a database for storing information." << endl;
ofstream myfile;
myfile. open ("data.txt", ios::app);
cout << "Please input what you want to store." << endl;
StringArray s;
std::string inString;
for (int i = 0; i < 5; i++ )
s.push_back(inString);
{
getline (cin, inString);
myfile << inString << endl;
}
std::sort (s.begin(), s.end(), greater<int>());
myfile. close ();
system("pause");
return 0;
}
There is rhyme and reason to formatting. Do it right and code is much easier to understand. Just correctly formatting your code points out a pretty obvious error with the for statement and the lines that follow.
Your conversation about strings and ints still doesn't make sense.
Last edited by GCDEF; June 1st, 2012 at 11:41 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|