0

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);

4iel
  • 11
  • 3
  • 4
    One reason for not `using namespace std;` is that it can get very confusing when you overload something that exists in the `std` namespace, like "fill" for instance. – molbdnilo Nov 24 '21 at 21:58
  • 1
    To be clear - this is the problem. Fixing this will solve your problem. [Why is "using namespace std;" considered bad practice?](https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice) – Drew Dormann Nov 24 '21 at 23:11

0 Answers0