Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- template<class T>
- void swap(T &a, T &b) {
- T temp = b;
- b = a;
- a = temp;
- }
- int main() {
- setlocale(LC_ALL, "ru");
- int i_1=10, i_2=20;
- float f_1=0.1, f_2=0.2;
- std::string string_1 = "один", string_2 = "два";
- char c_1 = 'a', c_2 = 'b';
- std::cout << "Первая переменная\t" << i_1 << "\nВторная переменная\t" << i_2 << std::endl << std::endl;
- std::cout << "Первая переменная\t" << f_1 << "\nВторная переменная\t" << f_2 << std::endl << std::endl;
- std::cout << "Первая переменная\t" << string_1 << "\nВторная переменная\t" << string_2 << std::endl << std::endl;
- std::cout << "Первая переменная\t" << c_1 << "\nВторная переменная\t" << c_2 << std::endl << std::endl;
- swap(i_1,i_2);
- swap(f_1, f_2);
- swap(string_1, string_2);
- swap(c_1, c_2);
- std::cout << "Первая переменная\t" << i_1 << "\nВторная переменная\t" << i_2 << std::endl << std::endl;
- std::cout << "Первая переменная\t" << f_1 << "\nВторная переменная\t" << f_2 << std::endl << std::endl;
- std::cout << "Первая переменная\t" << string_1 << "\nВторная переменная\t" << string_2 << std::endl << std::endl;
- std::cout << "Первая переменная\t" << c_1 << "\nВторная переменная\t" << c_2 << std::endl << std::endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment