السلام عليكم و رحمة الله و بركاته...
لدي برنامج و عندما أعمل له compile يظهر لي هذا الخطأ
hw02b.cpp:27: error: storage size of ‘word’ isn't known
فكيف أنشئ array of strings من غير معرفة الحجم إلا في الـ runtime ؟
#include <iostream>
#include <string>
using namespace std;
string smallest(string word[], int n)
{
string small;
if(n==0)
return 0;
else
{
if(word[n].size() < word[n-1].size())
{
small= word[n];
return smallest(word, --n);
}
else
return smallest(word, --n);
}
}
int main()
{
int length, n;
string word[];
cout<<"Enter a list of words on one line: "<<endl;
cin>>word;
length= word.length;
n= smallest(word, length);
cout<<"The smallest word is: "<<word[n];
return 0;
}