2011-11-29 62 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 –

相关问题