Как так сделать,чтобы текст вводить в консоли,а не в файле.txt
| Код | #include "stdafx.h" #include"stdafx.h" #include<iostream> #include<fstream> #include <string> #include <sstream> using namespace std; ifstream fin; class MyFile { private: string namefile; string s; string n; int len; public: MyFile(string name) { namefile = name;; } MyFile(string name,int size) { namefile = name; len = size; } void LenString() { fin.open(namefile); s = ""; n = ""; for(int i = 0; !fin.eof(); i++){ fin >> n; //cout << n << " "; s+=n + " "; } } void ConsoleOutPutFile(){cout << s << endl;} void Count(string s2){ istringstream ist(s); cout << "Kil:" << count(istream_iterator<string>(ist), istream_iterator<string>(), s2) << endl; } void Search(string s2){ istringstream ist(s); if(count(istream_iterator<string>(ist), istream_iterator<string>(),s2) > 0) cout <<"Yes" << endl; else cout <<"No" << endl; } }; int main(int argc, char **argv) { string s = "Txt.txt"; ofstream fout(s); //создание файла fout << "Text of c++ welcome text text worl no int char double" << endl;//запись текста fout.close(); MyFile file("Txt.txt");//открытие файла file.LenString(); file.ConsoleOutPutFile();//вывод на экран cout << "Conunt string \"col\" "; file.Count("of");//количество строки cout << "Search string \"of\" "; file.Search("of");//поиск строки cin.get(); }
|
|