Agni 370 Practically a Master Poster Featured Poster

1. Array Totaler: Given an integer array of size 50 (Filled with numbers read in from a file called “numbers.txt”, which is assumed to have 50 integer values), do the following: A) display the array to the screen (use 5 rows of 10 numbers each), B) ask the user how many numbers they would like totaled (error trap accepting only numbers between 1 and 50), C) Traverse the array recursively starting at the first element in the array and display each element in the array up to the number the user entered, and D) display the total of all the elements traversed.

As per this requirement I don't see any reason why you should be using a 2d array. You just have to read 50 integers in an array and the output a sum from 0-n. As far as displaying the array in 5 rows of 10 cols, that is just display and has nothing to do with a 2d array. So why are you making your life complicated? Use a 1d array and try recursion with that.

Agni 370 Practically a Master Poster Featured Poster

I use MS VC++6 and when I type code I have problem...let's say I have 123456789 typed and I place cursor between 4 and 5 and than type "something" I get 1234something and not 1234something56789

so it deletes and wont shift right :S

also enter doesnt brake new line,space,backspace....

I guess its some editor setting I need to tweak?

I agree, this is probably one of the stupidest questions asked here !!!

Agni 370 Practically a Master Poster Featured Poster

Not necessarily. You can have the other class as a private or protected member too or a pointer, or reference, depending on how you are going to use it.

I think it is composition, which if I'm not wrong is a type of association, but you should cross check that.

Agni 370 Practically a Master Poster Featured Poster

Yes you can do that, for example

class A
{
      public:
            int func() { return 1;};
};

class B
{
    public:
          A a;
};

int main()
{
         B b;
         b.a.func();
}
Agni 370 Practically a Master Poster Featured Poster

>>that is wrong. by start pushing from the front
2) start pushing in the stack from the start of the string

What is the difference between the 2 statements?

Agni 370 Practically a Master Poster Featured Poster

because c,c++ are the languages which are the base for learning other languages

Just over a week late or I could have celebrated my previous post's anniversary !! Leave this thread alone, it's too old now.

Agni 370 Practically a Master Poster Featured Poster

Another approach could be:

1. Read in a number as a string
2. Take one character from the front, convert it into a number and push it in a stack - Stack-1
3. Keep doing step 2 till you've pushed the entire string on the stack with the least significant bit at the top of the stack
4. Then do the same for the 2nd string - Stack-2
5. Then pop first element from both the stacks and add them and keep the result in another stack, Stack-3 and store the carry in a temporary
6. Pop the second elements from the stacks add them, and the previous carry, push the result on the Stack-3 and so on
7. Once you've done with one stack push the elements of the next stack, check for carries and add them if you have to and push the result on to Stack-3
8. Pop out Stack-3 to show result.

I have not thought over this completely, you can do a quick analysis to see if it fits your requirement. You could use a class to encapsulate all this stack handling and provide the user with just an add function. And there is a predefined std::stack class available which you can use.

Agni 370 Practically a Master Poster Featured Poster

Hey guys,

I'm new to C and I am trying to find a way to create a file with the following array:

And if you are trying to learn C, you'd be better off posting questions in the C forum or you might get a little mixed up.

Agni 370 Practically a Master Poster Featured Poster

Hey all! I have this assignment for my school project to create a simple address book using classes that do the routine stuff like adding a contact, searching it, modifying it, deleting it...
Here is the code but it won't run properly. I tried but couldn't figure it out. It'd be a huge help for me if you guys could have a look at it and tell me what and where the problem is...
Thank you! :)

Do you think it is easy for anyone to try and help you when you write stuff like 'it won't run properly' or 'i tried but couldn't figure it out' ?? If you tried you should write specifically what you tried so that we know. And what does it mean by 'it won't run properly' ? Which part works? Which part doesn't work? Am i supposed to go through your entire code and understand that? Don't you think giving these details are important? You're lucky AD has given you an answer, normally such posts will get no replies at all and rightly so.

Agni 370 Practically a Master Poster Featured Poster

You've passed the function pointer but where are you using it?

Agni 370 Practically a Master Poster Featured Poster

I have n!/((n-r)!r!)

which I figured out how to make recursive:

int crn (int n, int r)
{
	if (r==0||r==n)
		return 1;
	return (n-1)+(n-1,r-1);
}

how do I make it non-recursive?

what is this?? This is not a program, nor is it a recursive function and it does not calculate factorial. Did you even read this before posting it?

Agni 370 Practically a Master Poster Featured Poster
void SearchNames(string names[], int &rTotal, string &rNameONE, string &rNameTWO, 
				 int &rCount_NameONE, int &rCount_NameTWO, bool result_NameONE,
				 bool result_NameTWO)
{
	/* This is the search function that implements a basic brut force
	   search to find the specified names that the user inputs. */
	rCount_NameONE = 0;
	rCount_NameTWO = 0;

	result_NameONE = false;
	result_NameTWO = false;

		for(int i = 0; i < rTotal; ++i)
		{
		   //assume names[] is the array that holds the sorted names

		   if(rNameONE == names[i])
		   {
				 // Increment the counter to record occurences of name
				 ++rCount_NameONE;
				 result_NameONE = true;
				 continue;
			}
		   else if(names[i] > rNameONE)
		   {
			   break;
		   }
			else
			{	
				result_NameONE = false;
				//break;
			 }

		}


		   for(int j = 0; j < rTotal; ++j)
		   {
			   if(rNameTWO == names[j])
			   {
				   // Increment the counter to record occurences of name
				   ++rCount_NameTWO;
				   result_NameTWO = true;
				   continue;
			   }
			    else if(names[j] > rNameTWO)
				{
					break;
				}
				else
				{	
					result_NameTWO = false;
					//break;
				}

			}
		
}										

bool WriteOutput(string *pName, string names[], int &rIndex, string &rNameONE, 
				 string &rNameTWO, int &rCount_NameONE, int &rCount_NameTWO,
				 bool result_NameONE, bool result_NameTWO)
{
	/* The WriteOutput() function recieves the values that were passed to them
	   as well as the users input for the search and displays them to the
	   screen. This file also shows the user the output file for the results
	   and or summary of the outcome of the program. */
	
	// Declared Variables
	string filename = "FIRST-NAMES_SUMMARY.txt";
	result_NameONE = false;
	result_NameTWO = false;
	
	// This will make FirstNamesOutput cast as cin or cout
	ofstream FirstNamesOutput;										
	// Needed to open output …
Agni 370 Practically a Master Poster Featured Poster

nw chk my code plz. i have worked hard to do

Working hard is good but working smart is better !! There were a few more comments in the posts above which you didn't consider. setMaxSpeed should take an int argument like i mentioned above and not have couts to ask for input inside it. The overloaded ctor does not make sense if you ask for input speed inside the ctor. You should do that in main and pass the user given value to the ctor while creating the object. And again I would suggest that you do not declare t1 above and then overwrite it with another object, by calling the ctor manually. If you have to decide at runtime what kind of object to make use operator 'new' and declare t1 as a pointer.

Agni 370 Practically a Master Poster Featured Poster

Either define the cCourselist ctor or remove it's declaration from the class body so that the compiler is able to define one for the class

Agni 370 Practically a Master Poster Featured Poster

These are the 2 overloaded declarations of erase in vector:

iterator erase( iterator loc );
iterator erase( iterator start, iterator end );

Both of them take an iterator as argument and not int

Agni 370 Practically a Master Poster Featured Poster

Two constructors:
A default constructor: A constructor that initializes the attribute ms where ms is the maxSpeed.
An overloaded constructor: A constructor that takes ms as an argument, where ms is the maxSpeed.·

1-> You have not defined the overloaded constructor body.
2-> Are you sure you want to put all those couts in ctor? In my view for the default constructor you should simply initialize 'ms' to 250 and for the overloaded constructor, you should ask the user for the speed as input and pass it to the ctor.
3->Use ctor initialization list to initialize the values, it might not make much difference with an int but it is a good habit to develop.

Two methods:
() – return the maxSpeed value associated with the Train object.
setMaxSpeed(ms) – change the maxSpeed value associated with the Train object, where ms is the new value. ·

1->the setMaxSpeed method should have an int argument in it's signature which is the value to be set on 'ms'

Display the value through default constructor and overloaded constructor.·
Display setter value through main function

I really don't understand what kind of a requirement is this

train t1;
t1 = train()

Well I would never do that. I'm not sure what the standard says about this, and may be somebody else would confirm that, but I don't think it is a good habit to do this. You would be better off declaring t1 …

Agni 370 Practically a Master Poster Featured Poster

I think you have to re-implement this code from scratch, this just doesn't seem like an implementation of a binary tree. I would suggest that you read some tutorial on Binary trees before you start. Here are some good links Binary Trees , Binary search trees . Or just find some book and go through them and then try again.

Agni 370 Practically a Master Poster Featured Poster

I have the following code ( I'm creating a binary tree and then I want to print the values on it's leafs) but when I'm running it, it never enters in that if from the parcurgere function. What have I done wrong?

void creare(node *p)
{
	//your code
}
void parcurgere(node *p)
{
	if(p != NULL)
	{
		cout<<p->val;
		parcurgere(p->st);
		parcurgere(p->dr);
	}
}
void main()
{
	node *t = NULL;
	cout<<"dati radacina arborelui ";
	creare(t);
	parcurgere(t);
	
}

The function 'creare' does not change 't' , after the call 't' is still pointing to NULL and hence the 'if' condition in 'parcurgere' does not evaluate to TRUE. If you want 't' to point to a new object which is created in 'creare' then you should it pass the pointer by reference. So you function could be

void creare(node *& p)

And don't use void main

Dave Sinkula commented: Fast, cheap, good. Sounds like a winner to me. :) +13
Ancient Dragon commented: good answer +25
Agni 370 Practically a Master Poster Featured Poster

We do not do other people's assignment. If you try to do it on your own and get stuck then you can post the code here and ask specific questions about the problems you are facing. That's the way it works.

Agni 370 Practically a Master Poster Featured Poster

in case you are wondering, why you haven't got any useful replies, let me tell you. The question is vague, you have not provided any main function so we don't know which functions you want to call, how is your input stored and why you are not able to pass it to your class functions, you have started your post with a node::add_coupons function and provided several other function implementations which do not seem related to your question.

Agni 370 Practically a Master Poster Featured Poster

I don't thing it is overly complicated, seems neat to me. You could divide the class declaration and function definitions in different files, .h and .cpp and main could be in another 3rd file which includes graph.h and just uses whatever it wants to. You can define the structs edges and vertex as part of the graph class itself, since that is the one that uses them.

Agni 370 Practically a Master Poster Featured Poster

Maybe try -pedantic-errors

You need to specify the standard you are compiling against. The GCC defaults to using its own extensions. g++ -Wall -ansi -pedantic ... Hope this helps.

Thanks guys, -pedantic-errors option worked perfectly and gave an error on compilation. On using -Wall -ansi -pedantic i still get only a warning. So I guess I would have to configure my compiler to use -pedantic-errors.

It would be hard to believe but without this option it compiles even if 'i', in the above code, was uninitialized !!! I wonder what is the size of the array it is allocating in that case?

Agni 370 Practically a Master Poster Featured Poster

Thanks Dave, I tried -pedantic option and it is still only giving a warning to me. Shouldn't it be a nice and proper error? It is quite misleading. Can I ask which compiler and version you used?

> g++ -pedantic arrayTest.cpp
arrayTest.cpp: In function ‘int main()’:
arrayTest.cpp:6: warning: ISO C++ forbids variable length array ‘arr’

Agni 370 Practically a Master Poster Featured Poster

I don't know why you are getting this error, I would expect something like 'invalid use of non-static member in static function' error over here. Since getStaticGroupData is a static function of the class and mGroups is a non-static member of the same class and you are not allowed to access non-static members in a static function.

Agni 370 Practically a Master Poster Featured Poster
int main()
{
        int i=10;
        char arr[i];
}

I was expecting an error but it is compiling without any issues. I'm assuming the g++ compiler is doing something but not sure how to disable that. This is my compiler info

Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.4.1-4ubuntu8' --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared --enable-multiarch --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.4 --program-suffix=-4.4 --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --enable-targets=all --disable-werror --with-arch-32=i486 --with-tune=generic --enable-checking=release --build=i486-linux-gnu --host=i486-linux-gnu --target=i486-linux-gnu
Thread model: posix
gcc version 4.4.1 (Ubuntu 4.4.1-4ubuntu8)

Edit: I think i should mention that the error I was expecting was of using a non-const variable to declare the array size.

Agni 370 Practically a Master Poster Featured Poster

Oh that's nice! Thanks a lot I will try it out in a minute.

I think I'll go with vectors because vectors seem a bit simpler

Yes, that would be a good way to do it.

Agni 370 Practically a Master Poster Featured Poster

A very quick answer: You will have to use dynamic arrays

int* arr = new int[word.length];
Agni 370 Practically a Master Poster Featured Poster

how can i do dat plz guide me in detail

I don't think I can guide you in detail, it is a very basic concept of C++ and you should understand that thoroughly before you proceed. You can use Google to search for "pass-by-value + pass-by-reference + C++" and would surely get some good links. Then try it out and post back if you find any difficulties.

Agni 370 Practically a Master Poster Featured Poster

You are using pass-by-value semantics for passing method parameters as a result the changes you make, to the object, inside the functions have not effect on the actual object. Pass the parameters by reference and try.

Agni 370 Practically a Master Poster Featured Poster
int main()
{
	// Request and obtain valid decimal numbers
	int A = obtaindec('A');
	int B = obtaindec('B');

	// Convert A and B to binary and store as vector<char> arrays

	vector<char> Abin = dectobinstring('A', A);
	vector<char> Bbin = dectobinstring('B', B);

	// Create C based on the largest size of the other two
	vector<char> Cbin;
	if ( Abin.size() > Bbin.size() )
		Cbin.resize(Abin.size());
	else
		Cbin.resize(Bbin.size());
	int Cbinsize = Cbin.size();
	for ( unsigned int x = 0; x < Cbinsize; ++x )
		Cbin[x] = 48;

	// Now recalculate C as the result of relational operations
	// on A and B

	for ( unsigned int x = 0; x < Cbinsize; ++x )
		if ( Abin[x] == 49 && Bbin[x] == 49 )
			Cbin[x] = 49;

	cout << "\n\nA & B = ";
	 for ( unsigned int x = 0; x < Cbinsize; ++x )
		cout << Cbin[x];
	cout << endl;
}

Consider Abin to be of size 10 and Bbin to be of size 8 now according to your code since Abin.size() > Bbin.size(), Cbin is resized to Abin.size(), hence 10

Then jump to line 25, you have a loop which goes upto CbinSize, which is 10 and you end up accessing Bbin[8] which could either throw an error or end up giving out some garbage.

Jetsetivan commented: Concise help, thank you! +1
Agni 370 Practically a Master Poster Featured Poster

and shouldn't this

AdditionalWindows(*wxWindow parent);

be

AdditionalWindows(wxWindow* parent);

?

Agni 370 Practically a Master Poster Featured Poster

So your comparison is right but you need to declare sGuess as a 'char' data type. Then you can compare sGuess with sSelectedWord

char sGuess
Agni 370 Practically a Master Poster Featured Poster
void mainSPGameFunc() {

	readFileGetRandom();
	string sSelectedWord = readFileGetRandom(); 
	string sGuess;

	int iWordLength = sSelectedWord.length();
		
	cout << "Guess the word!\n";
	for(int i = 0; i < iWordLength; i++) {
		cout << "_ ";
	}
	
	cin >> sGuess;

	[B]for(int i = 0; i < iWordLength; i++) {
		if(sGuess == sSelectedWord[i]) {
			cout << "RIGHT!";
		}
		system("PAUSE");
	}[/B]
}

Since sGuess and sSelectedWord both are strings you could compare them by simply

if (sGuess == sSelectWord)

by doing sSelectedWord you actually point to the character that position in the string

Edit: just re-read your post..

and I set a for loop up to check if sGuess is the same as any letter in sSelectedWord

Do you want to compare sGuess with any letter of sSelectedWord? Not sure then what that means :( .. the answer above might not help. Probably you need to declare sGuess as a 'char'. Can you explain a bit more in detail?

Agni 370 Practically a Master Poster Featured Poster

Well that's one big code you've posted there, nobody can help you on that quickly, unless you clearly mark out a piece of code that is not working correctly or state your problem in much simpler manner or just about anything that makes one focus on some part of the code. It would take sometime and a really good heart for someone to completely understand your code and solve your problem.

Learn to use code tags

Salem commented: Well said! +18
Agni 370 Practically a Master Poster Featured Poster

Well the code is doing what it's supposed to do, but I don't understand this, why are you doing this on your 4th day of C++ ? If it's just a matter of this piece of code then may be it's ok but if this is how you are trying to learn C++, you are probably trying to make big leaps without understanding the basics.

Ans:
Operators >> and << are overloaded for your class type. when you typed 'hello' it got stored in the 'data' member variable of the class and when you do a cout, the overloaded operator returns the value of the same 'data' member variable.

Agni 370 Practically a Master Poster Featured Poster
template <typename T, typename LESS_THAN>
void RestrictedSet::insert (const T elem) 
{
  _S.insert (elem);
  if (++_size > _max_size) drop_worst(); 
}

The problem must be somewhere in the template part, I get the error:

agenda.cpp:28: error: ‘template<class T> class RestrictedSet’ used without template parameters
agenda.cpp:28: error: variable or field ‘insert’ declared void
agenda.cpp:28: error: expected nested-name-specifier before ‘T’
agenda.cpp:28: error: expected ‘(’ before ‘T’

I also tried variants like:

void <T, LESS_THAN> RestrictedSet::insert (const T elem)

Hope someone can help!

When you define a template function outside the class body you need to put the template types after the class name too,

RestrictedSet<T,LESS_THAN>::insert

secondly your insert statements signature doesn't match in the class body and definition, one uses a reference.

As an aside, Usually it is better to place the template function definitions in the same file as the class declaration and not make a different .cpp for it since most compilers do not implement a separation model for template compilation, atleast i tried on g++ 4.4.1 and it was not working.

Agni 370 Practically a Master Poster Featured Poster

Hi,

This is a very convoluted problem I spent hours debugging to find that when I call std::vector<object>::push_back(Object()) destructor of previous Object is called.

Is this the behaviour of std::vectors or is something wrong with my code?

It could be happening due to resizing of the vector. Once the limit of the vector exceeds it would allocate new storage, copy all the previous objects to the new storage and then delete the old one's. Try putting come cout in copy ctor and see it that's what's happening

this is obviously supplement to all the other advice niek_e has given.

Agni 370 Practically a Master Poster Featured Poster

Since sm_fileData is static member, wherever you are defining it, at that point the default ctor of class QFile is getting called and sm_fileData is getting initialized. You cannot call another ctor on it at any later point of time. You can try using the QFile's open function (cross check the documentation for this, i'm not 100% sure of the available fns) to attach it to the user given file name, if you know the file name at compile time, just initialize it with it at the first instance.

Agni 370 Practically a Master Poster Featured Poster

If you are really interested in learning C++ and becoming a good programmer, take all this advice constructively. Tomorrow when you go out to work in the professional world and do these mistakes, no one will point them out to you, they would probably just fire you. So, there's no point becoming all obstinate about your code, you are in-fact lucky that you got your code reviewed by such good programmers and got all this feedback.
Be wise and try to understand every bit of what's given and importantly, don't take your teacher's word as final.

xavier666 commented: nice one! +1
tux4life commented: Very nice suggestion :) +6
Agni 370 Practically a Master Poster Featured Poster

Well I did include the code...

class Foo
{
public:
	static void bar()
	{
		cout << "Foobar!\n";
	}
};
int main()
{

	//typedef void (*command)();
        typedef void (*command)(Manager*);
	typedef map<string, command> maptype;

	maptype cmdmap;

	cmdmap.insert(make_pair("bar", &Foo::bar));

	cmdmap.find("bar")->second();

}
cmdmap.insert(make_pair("bar", &Foo::bar));

this is the bar function declaration: void bar ();
this is the fn ptr you declared: typedef void (*command)(Manager*);

you cannot assign the address of a function which takes 0 parameters to a fn ptr of command type since it requires a Manager*. change the bar function to accept a Manager*

Agni 370 Practically a Master Poster Featured Poster

As earlier, it would have been better if you had posted the code that gave you the error. Somehow the descriptions don't really make the picture very clear !!

From the compiler error that you have posted it seems that probably you changed the function pointer to point to a function that takes a Manager* but did not make the changes to the function parameter list who's address you are assigning to that fn pointer. However, you've mentioned that It works with string and Manager, so that's confusing. If you can post the code which is giving the error, along with the headers included and the compiler error, we might be able to help better. It could be that the error is not where you think it is.

Agni 370 Practically a Master Poster Featured Poster

Well I would suggest you post the code which is giving the error, may be a pruned version with only the required fns and classes so we can exactly see what's happening. That's always much better.
normally declaring a function pointer to static member function does not require the class name to be put before the function pointer. It is declared just like a non-class function pointer, while assigning the address of the function we need the class name.

example: say i have a class 'A' with a static function 'void func(double)'

void (*pf)(double) = &A::func;
Agni 370 Practically a Master Poster Featured Poster

It is not clear from your post what exactly you wanted to do. Did you want a function pointer to a static class member function? That is not so difficult and in fact is same as non-class functions. However since the code you have posted does not contain any classes, I'm assuming you are trying something else. Can you tell us what the compiler error is that you are getting in this code? Is your code to insert the value into the map within the main or in global scope in your actual code?

Agni 370 Practically a Master Poster Featured Poster

rgpii i don't think you are reading any of the anwers carefully. I see the same mistakes in your code again, which I pointed out in my post earlier. If you don't read and apply what' been suggested then there's really no point.

Agni 370 Practically a Master Poster Featured Poster

It doesn't look like C++ code at all. And the moderators might prove that in sometime by moving it to the C forum !!

Agni 370 Practically a Master Poster Featured Poster
template <typename Type>
void dbList<Type>::insertNode(Type v)
{
	Node<Type>* tempa;
	Node<Type>* tempb;
	Node<Type>* tempc;
	tempa->data=v;
	
	if(this->head==0)
	{
		this ->head = tempa;
		this ->head ->next = 0;
		this ->head ->prev = 0;
		this ->size++;
		this ->head->position=size;
	}
	
	else  
	{
		tempb = this ->head;
	if(tempb ->next == 0)
	{	
		tempa->next = tempb->next;
		tempa ->prev = tempb;
		tempb ->next = tempa;
		this ->tail = tempa;
		this ->size++;
		this ->tail->position=size;
	}
	
	else
	{
		tempc = this ->tail;
		tempa ->next = tempc ->next;
		tempa ->prev = tempc;
		tempc ->next = tempa;
		this ->tail = tempa;
		this ->size++;
		tempc->position=size;
	}
	
	}
}

line 7: should be the first segmentation fault since 'tempa' is not pointing to anything and you try to deference it and assign value to 'data'

line11: this->head = tempa is also wrong, tempa is nothing, and you are assigning this->head to nothing, when you call display it'll probably crash again.

Probable solution:
Remove line 7.
Before you assign 'tempa' to this->head, create a new node and point tempa to it and then assign value to 'data'

something like

temp = new Node<int>();
Agni 370 Practically a Master Poster Featured Poster

InvalidArgumentException::InvalidArgumentException(class InvalidArgumentException const &)" (??0InvalidArgumentException@@AAE@ABV0@@Z)

I think the problem is that your copy ctor is declared but not defined and somewhere you are trying to make a copy of your class 'InvalidArgumentException' .

InvalidArgumentException(const InvalidArgumentException&);

so you could either provide a copy ctor definition or remove any copy attempts from your code or remove this declaration from your code so that the compiler generates it for you when needed

Agni 370 Practically a Master Poster Featured Poster

IMO you should create those objects separately and then add them to the vectors and sets of the factory class. Factory, in your case (and very misleadingly), looks like a collection of all other types and I don't think you should create these objects in the Factory, rather, just create a Floor and it to the vector in Factory. So you probably first need to figure out the ctors for all the other classes.

Agni 370 Practically a Master Poster Featured Poster
Form1 ff = gcnew Form1();

it probably want's you to declare 'ff as a 'Form1*', but i could be wrong since i've never seen the 'gcnew' operator before.

Agni 370 Practically a Master Poster Featured Poster
string_in[j][i]!=un_lock[j]

un_lock is a string, and un_lock[j] is a 'char' at position 'j'. while string_in[j][j] is a string. hence the error. You are trying to compare a string with a char and the compiler tells you that it is not allowed.

You're 2nd attempt just changes the error because you do a non-allowed static_cast from string to int. it has not solved any problem. The compiler, on both the occasions, clearly tells you what the problem is, but you're not reading the compiler output carefully. Simply shooting in the dark won't help.

from your comment, it seems that you need to compare each string in the array with the un_lock string and for that you could just do

string_in[j][i]!=un_lock