Çevreyi aradım ve kodlama projesinde aldığım bir hatanın cevabını bulamıyorum. Bir kullanıcının bir isim girmesini isteyen bir program oluşturmaya çalışıyorum ve daha sonra bu yılın adı ne kadar yaygın olduğunu bulmak için 2012 yılında en popüler bebek isimlerini arayacaktım.Ancak, oldukça yaygın bir sorun gibi görünse de Ben çözemiyorum benim işlevlerden birini tanımlarken, bir sorunla karşılaştık İşte şimdiye kadar kod:.C++: "error: expected", 'or' ... 'before' ('token "
/*Description: The code below asks the user to input a baby name and then
finds the popularity ranking of that name for both boys and girls in the
year 2012.
*/
// INCLUDE DIRECTIVES
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>
// FUNCTION DECLARATIONS
std::string nameGet(std::string& userName);
/*PRECONDITION: n.a.
POSTCONDITION: Outputs the name provided by the user*/
int findPosition(std::string userName, int namePosition(0));
/*PRECONDITION: Takes a string variable
POSTCONDITION: Outputs the ranking number of said string variable within
the 2012 list of popular baby names*/
// Main Function
int main()
/*PRECONDITION: n.a.
//POSTCONDITION: Popularity ranking of name according to list of popular 21012
baby names*/
{
// Local Variables
std::string userName;
int boyNamePlace(0), girlNamePlace(0);
nameGet(userName);
std::cout << std::endl << userName << std::endl;
boyNamePlace = findPosition(userName, boyNamePlace);
girlNamePlace = findPosition(userName, girlNamePlace);
return EXIT_SUCCESS;
}
// FUNCTION DEFINITIONS
std::string nameGet(std::string& userName){
/*PRECONDITION: n.a.
POSTCONDITION: Outputs the name provided by the user*/
std::cout << "Enter name (capitalize first letter): ";
std::cin >> userName;
return userName;
}
int findPosition(std::string userName, int namePosition(0)){
/*PRECONDITION: Takes a string variable
POSTCONDITION: Outputs the ranking number of said string variable within
the 2012 list of popular baby names*/
// Local Variables
std::ifstream babyNames;
bool nameFound(false);
//Opens the .txt file
babyNames.open("babynames2012.txt");
if (babyNames.fail())
{
std::cout << "I/O Stream failure when attempting to open file.";
return EXIT_FAILURE;
}
else
{
std::cout << "Success";
}
for(namePosition = 0; nameFound == false; namePosition++)
{
return 0;
}
return namePosition;
}
Gördüğünüz gibi, bu Program hala derlendikten sonra herhangi bir hata olmadan nasıl çalışacağını kontrol etmek için birçok cout ifadesiyle devam eden bir çalışmadır. Başlıkta belirtilen hata iletisi, hem "bildirim" hem de "findPosition" int işlevinin tanımında görüntülenir.
Henüz bir hata ayıklayıcısını nasıl çalıştırdığımı bilmiyorum ve bu benim ilk kez gönderme işlemidir, bu yüzden biçimlendirme biraz bozuksa özür dilerim.
Eğer findPosition ('için varsayılan bir argüman sunmak' öyleyse sizin tanımını değiştirirseniz için demek istediniz Açıklama argümanından varsayılan argüman: [this] gibi bir şey (http://coliru.stacked-crooked.com/a/1a5b8e4761b5db9d) –
Hata ayıklayıcıları, sözdizimi hatalarında yardımcı olmuyor –