任何人都可以告訴我爲什麼對下面的變量所做的更改沒有被拉到main?如何從void(C++)返回多個值爲main(C++)
我很新,所以請保持簡單。
如果你需要更多的我的代碼讓我知道:d
void BannedWordsArrayCreate (string filePathInBanned, vector<string> bannedWords, vector<int> bannedWordsCount, vector<int> containsBannedWordsCount) {
cout << "Please enter the file path for the banned word list. (no extension.): " << endl; //User enters file name
cout << "E.g. C:\\Users\\John\\banned" << endl;
cin >> filePathInBanned;
filePathInBanned += ".txt"; //Takes User defined file name and adds .txt
ifstream inFile;
inFile.open(filePathInBanned,ios::in); //opens file
if (!inFile) //if file cannot be opened: exits function.
{
cerr << "Can't open input file." << filePathInBanned << endl;
exit(1);
}
else if (inFile.is_open()) //if file opens: puts file into vector.
{
string bw = "nothing"; //temporary string used to signal end of file.
while(!inFile.eof() && bw != "")
{
inFile >> bw;
if (bw != "")
{
bannedWords.push_back(bw);
}
}
}
inFile.close();
cout << endl << "Done!" << endl << endl;
for(int i = 0; i < bannedWords.size(); i++)
{
bannedWordsCount.push_back(0);
containsBannedWordsCount.push_back(0);
}
}
謝謝,幫助了一堆。有趣的是它只是一件小事。 –
@ Kiku-Suma歡迎您。上面的一些額外的反饋。乾杯。 –