list of string

G

Gandalf

hi,
there is some function to verify that a string is already in the list or i
have to make a cicle?
thank u
 
G

Gavin Deane

Gandalf said:
hi,
there is some function to verify that a string is already in the list or i
have to make a cicle?
thank u

#include <iostream>
#include <string>
#include <list>
#include <algorithm>
#include <iomanip>
using namespace std;

int main()
{
const string is_in_list = "is in list";
const string is_not_in_list = "is not in list";

list<string> my_list;
my_list.push_back(is_in_list);

cout << boolalpha;

bool found = (find(my_list.begin(), my_list.end(), is_in_list) !=
my_list.end());
cout << found << "\n";

found = (find(my_list.begin(), my_list.end(), is_not_in_list) !=
my_list.end());
cout << found << "\n";
}

Does that help?

Gavin Deane
 
D

Daniel T.

Gandalf said:
hi,
there is some function to verify that a string is already in the list or i
have to make a cicle?

if ( find( lst.begin(), lst.end(), myString ) != list.end() )
// string is in the list
else
// string is not in the list
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top