Search within a stringk

closed account (o10S216C)
okkk
Last edited on
To find characters in the string, you can use one of the find() methods of the string class.
You could use std::sort() for the second part, but if you have to use bubble sort you'll probably want to find some code somewhere and copy it after studying how it works. Then simply call in on your string. You may need to create a C-style string copy to do this.
closed account (o10S216C)
would strchr work better in this case for finding a character.
strchr() is for C-style strings and you are using C++ strings, so no, I would not recommend it.
closed account (o10S216C)
http://www.cplusplus.com/reference/string/string/find/
how would i make it work in my program?
closed account (o10S216C)
Okay i got the search down, now how do i use bubble sort to sort an array? The only thing i can find is how to sort an int.
closed account (o10S216C)
How can i search for the last character in my string array?
Last edited on
You want the last particular character, or just the last character?
http://cplusplus.com/reference/string/string/rfind/
http://cplusplus.com/reference/string/string/rbegin/
closed account (o10S216C)
let me check it out
Last edited on
closed account (o10S216C)
How would i sort a word(no spaces) in abc order using a string?
closed account (o10S216C)
okk
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main() 
{

    cout << "Enter a string: ";

    string input = "";
    getline(cin, input);
    cout << "Your string was: " << input << endl;
    
    sort(input.begin(), input.end());
    cout << "Your string is: " << input << endl;
    system("pause");

	
	return 0;
}


This will be a good starting point for you I think.
Topic archived. No new replies allowed.