I am trying to gather and store user metadata for a project, but I can not find a way to store the length (number of characters) of a string.
int main()
{
string foo;
int bar;
size_t TryEverything;
cout << "Enter some random text: ";
getline(cin, foo);
bar = foo.size(); //Does not work
bar = foo.length(); //Does not work
bar = TryEverything.size(); //Does not work
bar = TryEverything.length(); //Does not work
}
I want bar to equal the numbers of characters (including whitespace) the user enters. Any suggestions?
I am currently using visual studio 08, and the debugger throws this error:
"Expression: deque iterator not dereferencable."
Edit:
The error was coming from somewhere else in the code. Foo should actually work.
TryEverythingissize_t, does size_t have membersizeandlength?dequein your code either.bar = foo.size();"not work" (besides probably giving you a warning about a narrowing conversion?)