Help with a program in Code:Blocks

Hey everyone! I want to create a program. That program it must read a name (characters) and if the name is different with the name which I choose it display a message (wrong name). If the name is correct it display another message. Can anyone help me?? This program is in Code:Blocks
if name1 != name2
//some code here
else
//some code here
What IDE you use doesn't make a difference
I would read the userdata into a string and then search the string for what you are looking for.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
//set up variable userdata... the next two lines may or may not work
//you may need to make a char then typecast it to a string
string userdata;
cin.getline (userdata,256);


string name = "name you choose";

if(userdata.find(name,0) != string::npos){
//whatever should happen if found
}
else{
//what should happen if not found
} 
Last edited on
Thanks for all answers.

@cscho

I copy your answer into my program but I have errors because probably I didnt choose the write library. See my program

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
//istream getline
#include <iostream>
#include <string>

using namespace std;

int main() {


string userdata;
cout << "Bres to onoma tis kopelas moy ";
cin >> userdata;


string name = "Eutuxia";

if (userdata.find(name,0) != string::npos) {
    cout << "\nTO BRHKES!!!!! S'AGAPAW MIKROULI MOY!!!!!!!<3<3<3<3";
}//if
else {
    cout << "\nSugnwmi.....Lathos.......:'( 3ana dokimase an 8eleis.....";
}//else



}//main 


I've changed some things and it works!! Thank you for helping me!!!! :P
Last edited on
Thanks again for helping me. Now I want to convert the *.cpp file into *.exe file. I have installed the Microsoft Visual Express 2010 but I can't compile it in *.exe file.

I appriciated if you give me some steps to do it.

Thanks again.
Topic archived. No new replies allowed.