Directory Listing | |
---|---|
isstream.cpp
|
|
namelist.txt
|
|
osstream.cpp
|
|
result.txt
|
|
string_reverse.cpp
|
|
strings_reverse.cpp
|
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
#include <iostream>
#include <sstream>
const int SIZE = 5;
using namespace std;
void reverse_string(string &);
int main() {
double values[SIZE] = { 1, 2, 3.4, 5, 357298.1 };
istringstream sout;
for (int i = 0; i < SIZE; i++) {
sout << values[i] << ", ";
}
string line = sout.str();
reverse_string(line);
cout << line << endl;
}
void reverse_string(string &str) {
char temp;
int end_pos;
for (int i = 0; i < str.length() / 2; i++) {
end_pos = str.length() - i - 1;
temp = str[i];
str[i ] = str[end_pos];
str[end_pos] = temp;
}
}