regarding string

Hi guys, I'm wondering why my string.length() doesn't work.
#include <iostream>
#include <map>
#include <string>

using namespace std;

int main()
{
typedef map<char,string> CharStringMap;
CharStringMap table;
table['a']="2";
table['b']="2";
table['c']="2";
table['d']="3";
table['e']="3";
table['f']="3";
table['g']="4";
table['h']="4";
table['i']="1";
table['j']="1";
table['k']="5";
table['l']="5";
table['m']="6";
table['n']="6";
table['o']="0";
table['p']="7";
table['q']="0";
table['r']="7";
table['s']="7";
table['t']="8";
table['u']="8";
table['v']="8";
table['w']="9";
table['x']="9";
table['y']="9";
table['z']="0";
string phoneNumber;
int x=0;
int i=0;
int t=0;
string word="";
string translation="";
string answer="";
bool hasAnswer=false;
while(true)
{
getline(cin,phoneNumber);
if (phoneNumber=="-1") break;
hasAnswer=false;
cin >>x;
for (i=0;i<x;i++)
{
cin >>word;
size_t size=phoneNumber.length(); (why the .length() doesn't work here??)
for(t=0;(t<phoneNumber.size());t++)
{
cout <<phoneNumber<<endl;
cout <<(phoneNumber.at(t))<<endl;
translation.append(table[(phoneNumber.at(t))]);

cout <<translation<<endl;
if ((phoneNumber.find(translation)!=0))
{
answer.append(word);
answer.append(" ");
hasAnswer=true;
}
}
if (hasAnswer)
{
cout <<answer<<endl;
}
else
{
cout <<"No solution"<<endl;
}
}
return 0;
}

For example, if I input
42389574829
.length() doesn't work for me.

Thanks
Last edited on
What does it output?
Topic archived. No new replies allowed.