String * type checking

Why does my code think that 3 is a string?

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
27
28
 //To receive the Student information
void inputStudentInfo(string *names, int *movies, const int numStuds)
{
	for(int i =0; i < numStuds; i++)
	{
	  cout << "Enter student name: "; getline(cin, names[i]); read_string(names[i]);
	  
	  cout << "Enter the number of movies for " << names[i] << ": "; cin >> movies[i]; cin.ignore(100, '\n');
		
	}
}

//Data-Type Checking for strings
string read_string(string Sname)
{


  while(!cin.good())
  {
    cin.clear();
    cin.ignore(80, '\n');
	cout <<"NOT A NAME" << endl;
  }
	cout << "WTF WE THOT THAT WAS A NAME!" << endl;
    return Sname;
}



If I type in 3 for the Student Name, the program just proceeds forward like nothing bad happened. I know this is something simple here. What am I screwing up?


Enter Student Name: 3
WTF WE THOUGHT THAT WAS A NAME!
Enter the numbers of movies for 3:


What do you think this code does??

std::string three = "3";
Anything that can be represented as text can be a string.

"3" can be represented as text. So it's a string.
Lol ^^ that's what I thought...Confused on how I'm going to check it though.
Why do you want to discriminate against people with numbers in or as their name?

http://www.kalzumeus.com/2010/06/17/falsehoods-programmers-believe-about-names/

This is not a joke and is not meant to be funny, it's a real thing: people can have names you would not expect.
Last edited on
^ Good point LB. LOL. I'm going to look into that asap.


I just set up a boolean to fix my problem though.
That's a pretty vague statement.
Topic archived. No new replies allowed.