2016-04-07 25 views
0

したがって、私はこの大きなプログラムを私の代入のために救済する必要がありますが、関数内でこの文字列配列のために得ているエラーを理解できません。 CONSTのchar * 『タイプのエンティティに割り当てることができません『のstd ::私が含まれた文字列*』
:「値のタイプIエラー
」エラーを得続ける 』 stockSymbol =の=で
「」」文字列が定義されている場所と関数です。誰でも何が起きているか、どのようにこれを修正するかについてのアイデアはありますか?配列文字列の関数エラー

int menu() 

{ 
int actents = 0; 

int opt = 0; 

string stockSymbol[MAXENTS]; 

double stockShares[MAXENTS]; 

double stockPrice[MAXENTS]; 

int opt; 

string opts; 

void resetPortfolio(string stockSymbol[], double stockShares[], double stockPrice[], int & actents) 

{ 
    // code logic to set all entries of the stock symbol array to "" 
    stockSymbol = "\"\""; 
    // code logic to set all entries of the other arrays to 0 
    stockShares = 0; 
    stockPrice = 0; 
    // set the number of actual entries in the arrays (actents) to 0 
    actents = 0; 
    return; 
} 
+1

"" \ "\" "は必要ありませんか? – anishthecoder

+0

C++はちょっと変わっているので、関数宣言の 'string stockSymbol []'は 'string'sの配列ではなく'文字列 's。 – immibis

+0

私はあなたが "\" \ "" 'を意味していると仮定し、そこに置いてください。ただし、std :: stringにintを代入することはできません。 –

答えて

0

あなたの機能menuは閉じられていません。

string stockSymbol[MAXENTS]; 

double stockShares[MAXENTS]; 

double stockPrice[MAXENTS]; 

menuですか?

""""は、文字列""を意味します。 2つの文字列を一緒に書くと、文字列の連結を意味します。値で配列を埋める設定する

for(var i=0; i<MAXENTS; i++) 
    stockSymbol[i]="\"\""; 
for(var i=0; i<MAXENTS; i++) 
    stockShares[i]=0; 
for(var i=0; i<MAXENTS; i++) 
    stockPrice[i]=0; 
1

stockSymbolstockShares、及びstockPriceは、すべての配列の最初の要素へのポインタです。要素の値を設定するだけでは、それらを割り当てることはできません。その代わりに、配列をループして各要素の値を設定する必要があります。

void resetPortfolio(string stockSymbol[], double stockShares[], double stockPrice[], int & actents) 
{ 
    for (int i = 0; i < actents; ++i) { 
     // code logic to set all entries of the stock symbol array to "" 
     stockSymbol[i] = ""; 
     // code logic to set all entries of the other arrays to 0 
     stockShares[i] = 0; 
     stockPrice[i] = 0; 
    } 
    // set the number of actual entries in the arrays (actents) to 0 
    actents = 0; 
} 

投稿したコードには他にも問題があります。 menu()は決して閉じず、実際にはresetPortfolio()に電話をかけることはありません。

+0

さて、ありがとう、これはそれを修正し、どのように私はエントリをコーディングしていた必要があります理解するのに役立ちました。そして、申し訳ありませんが、これはコードのちょっとした些細なものでした。この大きな巨大なもので、私は必要と思ったものに切り詰めようとしていました。 –

+0

@ReyH無関係なものは切り取るのが良いですが、残っている部品は意味をなさないことも重要です。 –