これが漠然としていたらすみません、私はまだプログラミングにかなり慣れていません(フォーラムも初めてです>_>)
わかりました、私のコードはファイルから数値を読み取り、その数値を使用してその量の単語を辞書の単語として読み取ることになっています。次に、それらの単語を配列に格納し、後で使用できるように保持します。ファイル内の辞書の単語がいくつかの段落になった後、それを読み取り、それを c-string 配列に設定します (iv はこれまでのところすべて理解しています)。 -string と各辞書の単語が出現する回数を数えます。現在、paragraph.find (word[0]) を試していますが、修正方法がわからないエラーが発生します。
エラー: |40|エラー: 'paragraph' 内のメンバー 'find' の要求は、非クラス型 'char [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 は次のようになります。
3ステーキ|卵|と|
ステーキと卵と卵とステーキ、卵とステーキ、ステーキと卵...
おいしい。