Прочитайте файл, содержащий числа с плавающей запятой, скомбинируйте пары прочитанных чисел в комплексные значения и выведите их.
Ну от примерно что то сделал.
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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
#include <iostream> using std::cout; using std::endl; using std::ios; using std::cerr; #include <fstream> using std::ifstream; #include <string> using std::string; #include <cstdlib> using std::exit; #include <vector> using std::vector; #include <algorithm> using std::for_each; #include <cctype> using std::ispunct; void fun(string s) { cout <<"a= "; for(int i=0;i<s.size();i++) { if(ispunct(s[i])) { cout <<" b= "; continue; } cout <<s[i]; } cout <<endl; } int main() { ifstream r("text2.txt", ios::in); if(!r) { cerr <<"don't open file"<<endl; exit(1); } vector<string> v; string s; while(r >>s) { v.push_back(s); } // for(int i=0;i<v.size();i++) // cout <<v[i]<<endl; for_each(v.begin(),v.end(),fun); return 0; } |
[youtube]http://www.youtube.com/watch?v=ojpwH8tj-Z8[/youtube]