大学の課題です・・
キーボードから“stop”と入力するまで繰り返し文字列を読み込みファイルに書き込んでゆくプログラムを作りたいんですが・・・教えてください。お願いします!!!!
無題
Re:無題
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <iterator>
template<typename I, typename O, typename P>
O copy_stop(I b, I e, O d, P p) {
while (b!= e) {
if (!p(*b)) throw "stop";
*d++ = *b++;
}
return d;
}
bool p(const std::string& s) { return s != "stop"; }
int main() {
std::istream_iterator<std::string> b(std::cin), e;
std::ofstream f("word.txt");
std::ostream_iterator<std::string> o(f, "\n");
try{ copy_stop(b, e, o, p); } catch (...){}
return 0;
}
#include <fstream>
#include <string>
#include <algorithm>
#include <iterator>
template<typename I, typename O, typename P>
O copy_stop(I b, I e, O d, P p) {
while (b!= e) {
if (!p(*b)) throw "stop";
*d++ = *b++;
}
return d;
}
bool p(const std::string& s) { return s != "stop"; }
int main() {
std::istream_iterator<std::string> b(std::cin), e;
std::ofstream f("word.txt");
std::ostream_iterator<std::string> o(f, "\n");
try{ copy_stop(b, e, o, p); } catch (...){}
return 0;
}
Re:無題
質問がアレなんで私もSTLで書こうかと一時は思いましたが、嫌味が
過ぎるので思いとどまりました。
EXE > RECORD.TXT とりダイレクトして使用してください。
過ぎるので思いとどまりました。
EXE > RECORD.TXT とりダイレクトして使用してください。
#include<stdio.h> #include<string.h> int main(void){ char buff[8]; const char stop_keyword[/url] = "stop\n"; while(fgets(buff, sizeof(buff), stdin)){ if(strcmp(buff, stop_keyword) == 0) return 0; printf(buff); } return 1; }