大規模なCSVファイルに対して複数のプロセスを一度に実行するためにasync関数を使用して、長い待ち時間を避けようとしましたが、エラーが発生します:オーバーロード機能のインスタンスがありません "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'はまた、すべての機能を介して基準によって周り渡されるグローバル変数です。この時点で、グローバルである必要はありません。また、グローバル変数とその変数への参照に同じ名前を使用しています。それはあまりにも混乱するビットをクリアするだろう。 –