-2
私は文字列変数を追加、削除、編集することができるシンプルなデータベースプログラムを作ろうとしています。C++ if(Array [x] .length> 0)
私は次の問題に遭遇しました:追加された各変数を次の空の配列要素に割り当てます。
- 私は動的配列についてもっと学ぶまで静的配列を使っています。
- 文脈から外れているので、ここでコードを再作成して、意味が分かりました。申し訳ありませんが、私は何かを見逃しました。
//static array declaration
std::string names[5];
//string selection from main function
std::string stringSel = "Item";
//boolean condition for loop
bool completed = false;
//if (names[x].length > 0) then increment x by 1 until names[x].length == 0 and then set that array element to the value from stringSel
int x = 0
while(completed == false)
{
//if the length of the element is greater than zero characters, increment the element
if (names[x].length > 0)
{
x++;
}
//if the length of the element is not greater than zero characters, set the string to that element
else
{
//The empty element is assigned the string and the entire array prints out
names[x] = stringSel;
std::cout << stringSel << " was added to the database.\nThis is the printout of all current items: " << names;
completed = true;
}
}
エラーはif文の条件から来ています。 '。'赤
1 IntelliSenseの下線が引かれている:バインドされた関数へのポインタのみ
ありがとう、それは簡単に解決して意味があります。 stdクラス、オブジェクト文字列、長さメンバーですか?私は最近、クラスとオブジェクトの仕組みを学びました。 –
@Bijan Kelleyようこそ。 'std'は' string'クラスが属する名前空間で、 'length()'は 'string'クラスのメンバ関数です。この場合の 'string'クラスのオブジェクトは、' std :: string names [5]; 'のような配列を作成するので' names [x] 'が保持するものです。 –
あまりにもそれをクリアしていただきありがとうございます!先週もネームスペースについて学んだので、ちょうど1つの石で2匹の鳥を殺したようです。 –