2019/c++

strings(3)

fw93 2018. 3. 22. 16:43
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include "stdafx.h"
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
 
using namespace std;
 
void reverse(char * tmp) {
    char * end = tmp;
    while (*end) {
        end++;
    }
    end--;
    while (tmp < end) {
        char t = *tmp;
        *tmp = *end;
        *end = t;
        tmp++;
        end--;
    }
}
 
int main() {
    string s1 = "hello meme";
    char * tmp = &s1[0];
    reverse(tmp);
    //sort(s1.begin(), s1.end());
    printf("%s\n", s1.c_str());
    while (1) {}
    return 0;
}
cs


'2019 > c++' 카테고리의 다른 글

list inserts and deletes  (0) 2018.03.24
string manipulations ( pointers )  (0) 2018.03.22
Strings(2)  (0) 2018.03.22
relational data structures & strings (C++ STL)  (0) 2018.03.21
dynamic allocation of 2-dimension array  (0) 2018.03.20