main()
2 つの関数を実行する 2 つのスレッドを作成 しようとしています。
vow
- 母音で始まる単語を出力しますcons
- 子音で始まる単語を出力します。
これらの単語はテキスト ファイルから取得され、ベクトルに読み込まれます。現在のコードは単語を正しい順序で出力しますが、すべての単語を母音で始まる単語としてラベル付けしています。テスト文を使用しています:"Operating Systems class at college."
現在、すべての母音をチェックしている if ステートメントを O (大文字の o) のみをチェックするように変更した場合、「Operating」は正しい母音としてラベル付けされ、残りは子音としてラベル付けされます。何がうまくいかないのですか?
同期技術の使用は許可されていません。
#include <iostream>
#include <thread>
#include <fstream>
#include <string>
#include <iterator>
#include <vector>
#include <sstream>
using namespace std;
int cons(string temp){
cout << "cons: " << temp << endl;
//this_thread::yield();
return 0;
}
int vow(string temp){
cout << "vow: " << temp << endl;
//this_thread::yield();
return 0;
}
int main(){
string sentence, temp;
ifstream ifs;
ofstream ofs;
vector <thread> wordThreads;
ifs.open("phrase.txt");
getline(ifs, sentence);
istringstream s(sentence);
istream_iterator<string> begin(s), end;
vector<string> words(begin, end);
ifs.close();
for(int i=0; i<(int)words.size(); i++) {
temp = words[i];
if(temp[0] == 'A'||'a'||'E'||'e'||'I'||'i'||'O'||'o'||'U'||'u') {
thread threadOne(vow, temp);
threadOne.join();
}
else {
thread threadTwo(cons, temp);
threadTwo.join();
}
}
}