script won't work

Even when input does equal exit it won't break

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>

using namespace std;

char input[200];

int main()
{
	while(1)
	{
		cout<<"Command: ";
		cin>>input;
		if (input=="exit")
		{
			break;
		}
	}
return 0;
}
I think I've posted this link no less than five times this week: http://www.cplusplus.com/reference/clibrary/cstring/strcmp.html
Last edited on
I'm using iostream.
What's your point?
I'm a noob to c++.
I'm still trying to just figure out iostream.


Very hard....
Last edited on
Don't be smart.

You are using an array of char. How you fill it makes no difference. You cannot compare the whole content of two different arrays with == .

Think about the advice given you and try not to find yourself on people's "ignore list" by being ignorant.


As a friendly offering, you should consider using std::string instead of char[]. Only then can you do cool stuff with operators.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#include <string>
using namespace std;

string input;

int main()
{
    while (true)
    {
        cout << "Command: ";
        cin >> input;
        if (input == "exit")
        {
            break;
        }
    }
    return 0;
}

Good luck.

[edit] It seems this conversation is a little more ripe than I thought ;->
Helios is right to be annoyed, so all I mean is you can show some tact and consideration when asking for and receiving answers. That's all.
Last edited on
well sry, but currently I'm just trying to master iostream before trying new things in c++ cuz c++ is already hard enough..
Last edited on
Oh, I wasn't annoyed. Not at him, anyway.
Although I do wish more people took the time to learn the syntax and learnt to read references.
== to compare strings... Thank you very much, BASIC. Thank you very much.
Just kidding. It's the teacher's fault, not BASIC's.

Master iostream? Now, that's some endeavor. For a beginner, anyway.
Last edited on
Its hard enough with just iostream.

I haven't even figured out what classes are.
Last edited on
O... kay...
It seems that this has gone a little off-topic.
What does iostream have to do with comparing C strings?
For that matter, what do classes have to do with comparing C strings?
Finally, you wouldn't happen to be picking the contents of your replies through some sort of chance-based method, would you?
Last edited on
I said "Its hard enough with just iostream. I haven't even figured out what classes are." because that is where I am at in learn C++.

Also my C++ book said that in order to store string you use char

for example:
 
char teststring[200]
Last edited on
That's all fine and good, but it's completely off-topic, since you don't need neither classes nor iostream to compare C strings.
This function is all you need to compare C strings: http://www.cplusplus.com/reference/clibrary/cstring/strcmp.html
If there's something about it you don't understand, you can come back and ask.

And I am well aware of what C strings are, thank you. I don't think I'll need to be reminded any time soon.

(See, Duoas? Now I am annoyed.)
Er, well... It does appear that he is as green as they come.

I don't see anything particularly off-topic about trying to figure out how to relate input and strings --it is part of his original premise so I think it fair to ask about it.


I don't know what book you are reading, but keep working through it. If you try to do something beyond what you have worked your way through so far, and it doesn't quite work, just put it aside for a while and keep working your way through the book. Either you will directly cover the topic eventually, or you will learn enough to be able to work it out yourself. Don't get too frustrated at the start.

Of course, us jerks will be here to help if you get really lost on something. :-)
Topic archived. No new replies allowed.