我想用异步函数在一个大的csv文件上一次运行多个进程,以避免长时间等待用户但是我得到的错误:没有实例的重载函数“async”匹配参数列表
no instance of overloaded function "async" matches the argument list
我已经搜索了一下,没有发现任何修复它,并出于想法,因为我很新的编码C++任何帮助将不胜感激!我在下面列出了所有的代码。
#include "stdafx.h"
#include <cstring>
#include <fstream>
#include <iostream>
#include <string>
#include <algorithm>
#include <future>
using namespace std;
string token;
int lcount = 0;
void countTotal(int &lcount);
void menu()
{
int menu_choice;
//Creates the menu
cout << "Main Menu:\n \n";
cout << "1. Total number of tweets \n";
//Waits for the user input
cout << "\nPlease choose an option: ";
cin >> menu_choice;
//If stack to execute the needed functionality for the input
if (menu_choice == 1) {
countPrint(lcount);
} else { //Validation and invalid entry catcher
cout << "\nPlease enter a valid option\n";
system("Pause");
system("cls");
menu();
}
}
void countTotal(int &lcount)
{
ifstream fin;
fin.open("sampleTweets.csv");
string line;
while (getline(fin, line)) {
++lcount;
}
fin.close();
return;
}
void countPrint(int &lcount)
{
cout << "\nThe total amount of tweets in the file is: " << lcount;
return;
}
int main()
{
auto r = async(launch::async, countTotal(lcount));
menu(); //Starts the menu creation
return 0;
}
'lcount'是一个全局变量,也由各地参照通过所有功能通过。在这一点上,它不需要是全球性的。此外,您正在为全局变量和对该变量的引用使用相同的名称。它会清除那个令人困惑的位。 –