C++ で書かなければならないのは、たまにしかありません。私の問題は、文字列内の文字列をどのように見つけるかです。次に、その行を保存し、その行で一連の数値を探します。たとえば、次のようなテキスト ファイルがあります。
住所 長さ 名前 87623498 2 犬 12345678 4 猫 98737289 1 鳥
「cat」を検索し、それに関連付けられた番号 (12345678) と (4) を別の変数名に格納したいと考えています。ここに私が書いたいくつかのコードがありますが、それは正しいとは言えません。この DLL を呼び出す .exe があります。どんな助けでも大歓迎です!` #include #include #include #include #include
char* File_Path; //Path is sent by another program
char* Name; //value is being sent by another program
unsigned long Address;
int Length;
int found = 0;
{
using namespace std;
std::string Line;
std::ifstream infile;
infile.open (File_Path);
if (infile.is_open())
{
std::ofstream outfile;
outfile.open ("C:\\debug\\test.txt")
while (infile.good() && found == 0)
{
std::getline(infile,Line);
//if (Name is within Line){
/*I want to say IF char* Name = a part of the string line
ie. Name = cat and the string Line is (12345678 4 cat)
Then store the number (12345678 = Address), and
(4 = Length) I hope that makes sense :/
*/
outfile << Line; //output the stored line for debug
outfile << address; //output the stored address for debug
outfile << length; //output the stored length for debug
found = 1;
}
outfile.close();
infile.close();
}
return 0;
}
「助けてください!ありがとうございました!