Anonymous error...!!!

10 views
Skip to first unread message

Itban Saeed Usmani

unread,
May 12, 2013, 5:24:25 AM5/12/13
to cs1003-s...@googlegroups.com
A.O.A. 

In STL slides I found a code & I tried to compile it on my VS10 but it(copy paste code) is giving an anonymous error, here I'm attaching the screenshot image, Please check the problem.

Regards,
Itban Saeed Usmani
o.jpg

Sami Ullah Kashif

unread,
May 12, 2013, 6:30:39 AM5/12/13
to cs1003-s...@googlegroups.com
Have you included string, vector and algorithm header files. I copied and pasted the code too, its working perfectly fine for me. I am pasting the code below. Try this:

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{ vector <string> v; string s;
while (1)
{
      cout << " Enter lines of text that you want to sort:\n";
       getline(cin,s);
       if ( s == "stop")
break;
       v.push_back(s);
}
sort(v.begin(), v.end());
cout << " After sorting: \n";
for (int i=0; i < v.size(); i++)
cout << v[i] << endl;
return 0;
}

shahzaib saleem

unread,
May 12, 2013, 6:43:54 AM5/12/13
to cs1003-s...@googlegroups.com
AOA

 sir pleas explain the output of this code
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{ vector <string> v; string s;
while (1)
{
      cout << " Enter lines of text that you want to sort:\n";
       getline(cin,s);
       if ( s == "stop")
break;
       v.push_back(s);
}
sort(v.begin(), v.end());
cout << " After sorting: \n";
for (int i=0; i < v.size(); i++)
cout << v[i] << endl;
return 0;
}
regards
Shahzaib Saleem




--
You received this message because you are subscribed to the Google Groups "CS1003-Spring2013" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cs1003-spring2...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Sami Ullah Kashif

unread,
May 12, 2013, 7:23:29 AM5/12/13
to cs1003-s...@googlegroups.com
You shall first input the strings via the console. When you want to stop, you enter the word "stop" on the console. All these strings are stored in the vector. The sort function sorts those strings and then display them on the console one by one.

Regards,
Sami
Reply all
Reply to author
Forward
0 new messages