-
November 29th, 2011, 11:27 AM
#1
[RESOLVED] string question
hi all,
suppose i've a string that has abc like:
Code:
string str;
cin>>str; // user enters abc
for(int i=0; i<str.length(); i++)
{
//compare if str has 'a'
// loop continues till find all character by character
}
is it possible with string class to find character by character?
thanks..
-
November 29th, 2011, 11:32 AM
#2
Re: string question
Yes. Take a look at the interface of std::string.
-
November 29th, 2011, 11:34 AM
#3
-
November 29th, 2011, 12:30 PM
#4
Re: string question
Originally Posted by Aashi
hi all,
suppose i've a string that has abc like:
Code:
string str;
cin>>str; // user enters abc
for(int i=0; i<str.length(); i++)
{
//compare if str has 'a'
// loop continues till find all character by character
}
is it possible with string class to find character by character?
thanks..
As an aside to the question and responses already given, if you intend "cin >> str;" to put the whole line into str, then you might want to consider using
Code:
std::getline(std::cin, str);
since
will not put the whole line into str (it will only copy the first block of characters until it hits some white space) whereas std::getline will put the whole line into str.
-
November 29th, 2011, 12:50 PM
#5
Re: string question
thanks all,
can anyone tell me which member function should i use for this purpose? from this site http://www.cplusplus.com/reference/string/string/
i tried with find, compare..
-
November 29th, 2011, 12:57 PM
#6
Re: string question
Originally Posted by Aashi
thanks all,
can anyone tell me which member function should i use for this purpose?
Your description of what you want to do is not clear.
Let's start with this:
So what do you want to do with this string?
Regards,
Paul McKenzie
-
November 30th, 2011, 01:15 AM
#7
Re: string question
Originally Posted by Paul McKenzie
Your description of what you want to do is not clear.
Let's start with this:
So what do you want to do with this string?
Regards,
Paul McKenzie
i want to make a logic for converting infix expression to postfix expression: for this i need to have stack and string. I can use char array for this, i just want to try with string. So, how can i compare a character with a string having abc/e+ ??
thanks...
-
November 30th, 2011, 04:44 AM
#8
Re: string question
Originally Posted by Aashi
In the link: Look what they wrote after "Element access:"
Regards
PA
-
November 30th, 2011, 05:24 AM
#9
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
|