2011-11-29 22 views
0

我我還是很新的編程對不起,如果這是模糊的(也是新到論壇> _>)錯誤:請求中成員'發現「(CString的名字)」,這是無級式的「字符[2000]」

好吧,我的代碼應該從一個文件中的一些閱讀,然後用這個數字在詞作爲字典中的單詞的量閱讀。然後我將這些單詞存儲到一個數組中,並保留它們以備後用。在文件中的字典單詞出現某段後,我將它讀入並設置爲c-string數組。(但到目前爲止,所有內容都已被刪除)但是對於程序的最後部分,我需要返回該段落c字符串並計算每個字典單詞出現的次數。我目前正在嘗試paragraph.find(word [0]),但我得到一些錯誤,我不知道如何解決。

錯誤:| 40 |錯誤:請求爲成員「查找」在「段落」,這是無級型的「字符[2000]」 |

代碼:

#include <iostream> 
#include <fstream> 
#include <cstring> 
#include <windows.h> 

using namespace std; 

int main() 
{ 
    ifstream inStream; //declare ifstream 

    inStream.open("infile2.txt"); //open my file 

    int number;    // number at the begining of the file that lets the  program know 
    inStream >> number;  // how many dictionary words are to be expected. 
    cout << number << " dictionary word(s)" << endl << endl; 

    char dict[30]; 
    char text[2000]; 
    char paragraph[2000];  // declareing some stuff 
    int count; 
    int position; 
    string word[5]; 

    for (int i=0; i<number; i++) // using c string to set the 'number' amount of words in the dict array 
    { 
     inStream.getline(dict,30,'|'); 
     word[i] = dict; 
    } 

    for (int i=0; i<number; i++) // cout so i can see its all set up right. 
    { 
     cout << "word " << i+1 << " is: " << word[i] << endl; 
    } 
    cout << endl; 

    inStream.get(paragraph,2000,'|'); // setting the rest of the paragrapg of the txt document to a c string 
    cout << paragraph;    // so it can be searched later using the 'dict' words 

    position = paragraph.find (word[0]); // trying to find the position of the first word stored in 'dict[0]' but i run into an error 

    return 0; 
} 

的infile2.txt看起來是這樣的:

3steak |雞蛋|和|

牛排和雞蛋,雞蛋和牛排,雞蛋和牛排,牛排和雞蛋...

美味。

回答

1

c字符串不是類,並且沒有查找方法(或任何其他方法),例如paragraph.find。你可以嘗試使用一個字符串,或者如果你需要使用C字符串一個find方法,它將兩個c字符串作爲參數。

This one

+0

ohhh我看到.find是一個成員。感謝您的鏈接!我想我能理解<3 –

相關問題