Hi all,
I've been trying to find part of a string in a vector. The problem being that I can only get it to work if I enter the entire string, but I need it so that I only search for the first part of the string in the vector.
Here's what I've got:
int i =1;
while (i < 4000)
{
std::fstream file1("Chinese.txt");
std::vector<std::string> load;
std::stringstream integer;
integer<<i;
std::string thisString;
thisString=integer.str();
thisString.insert(0,"IDS_STRING");
while(!file1.eof())
{
std::string line1;
std::getline(file1,line1);
load.push_back(line1);
}
bool isPresent=std::find(load.begin(),load.end(),thisString)!=load.end());
if(isPresent==false)
{
file1<<thisString + "\t";
}
else {}
file1.close();
i++;
}
So what's happening here is that the file contains strings that begin with "IDS_STRING" followed by a number, a tab and then a command. I'm basically trying to go through the file and see if each IDS_STRING number exists, so from 1 to 4000, and if it doesn't I want to write a new line in the file with the IDS_STRING number.
Example file contents:
IDS_STRING3 "Exhaust in"
IDS_STRING10 "Actuator off"
IDS_STRING4 "Service"
And say, I search for IDS_STRING12, which doesn't exist, I'd want that line to be inserted into the file, so:
IDS_STRING3 "Exhaust in"
IDS_STRING10 "Actuator off"
IDS_STRING4 "Service"
IDS_STRING12
Now, I don't know what the second part of the string is going to be (the command) so can only search for the IDS_STRING part. How can I achieve that?
Thanks in advance