My code should work, but it isn't, I tried to add new agrs to fill, eth, also I have read the syntax of thread, and code should work.
How can I fix this? Also in IDE I can see that thread th1 should take 1 arg(string str)
using namespace std;
list <char> list_start;
list <char> list_finish;
void fill(string str )
{
int size;
size = str.size();
for (int i = 0; i < size; i++)
{
char ch = str[i];
list_start.emplace_back(ch);
}
}
void fill1(int N, int K)
{
int i = 0;
int t = 0;
while (i != (N - 1))
{
list_start.pop_back();
i++;
}
while (t != K)
{
list_finish.emplace_back(list_start.back());
list_start.pop_back();
t++;
}
}
void output()
{
while (!list_finish.empty())
{
cout << list_finish.back() << endl;
list_finish.pop_back();
}
}
int main()
{
string str;
int N, K;
cout << "Enter your sentence" << endl;
cin >> str;
thread th1(fill, str);
cout << "Enter N(sequence number)" << endl;
cin >> N;
cout << "Enter K(number)" << endl;
cin >> K;
th1.join();
thread th2(fill1, N, K);
th2.join();
thread th3(output);
th3.join();
return 0;
}
The problem is in line 54, thread th1(fill, str);