I read lines from file in separate strings, and i want to compare each first 3 characters from each strings with some text (mov,add,sub,mul).
Something like(i ned to figure out how to implement this code):
if (strncmp (all_lines[0],"mov",2) == 0)
{
//put ax into a char
// put 03 into a variable
// then ax=3
}
elseif (strncmp (all_lines[0],"add",2) ==0)
{
//put ax into a char
// put 03 into a variable
// then ax = 'another variable' + 3
}
elseif (strncmp (all_lines[0],"sub",2) ==0)
{
//put ax into a char
// put 03 into a variable
//then ax = 'another variable' - 3
}
elseif (strncmp (all_lines[0],"mul",2) == 0)
{
//put ax into a char
// put 03 into a variable
//then ax = 'another variable' *3
}
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
usingnamespace std;
int main()
{
ifstream myFile;
string line, *all_lines;
int line_count = 0;
myFile.open("instr.txt");
while (getline(myFile, line))
line_count++;
all_lines = new string[line_count];
int i = 0;
myFile.close();
myFile.open("instr.txt");
while (getline(myFile, line))
{
all_lines[i] = line;
i++;
}
for (i = 0; i < line_count; i++)
cout << all_lines[i] << endl;
if (strncmp (all_lines[0],"mov",2) == 0)
{
cout<<"found"<<endl;
}
}
My quest are:
1.In the main code , i get the error: "cannot convert str::strings{aka std::basic_string<char>} .
2.I need some advices about how i can to implement the compare strings code.