# Help with converting digits or symbols into numbers

Page 1 of 1

## 1 Replies - 411 Views - Last Post: 03 October 2012 - 07:28 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=294167&amp;s=808bc1ebe6c8a275fc6892a8a20d5176&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 Tom_Dub

Reputation: 0
• Posts: 1
• Joined: 03-October 12

# Help with converting digits or symbols into numbers

Posted 03 October 2012 - 05:32 PM

Hey all,

I'm a little confused on the proper method for converting symbols and what not into numbers.

For example, writing a program that reads from a file.

Say the file has input: \$7,5,21%!87,9!8.32

I'd want the output to be on 3 separate lines as;

7521
879
832

So far this is the code I have below:

```int main()
{
char ch;
ifstream inFile;
ofstream outFile;

infile.open ("Sample.txt");
if (not inFile)
{
cout<<"failure to open sample.txt"<<endl;
system("Pause");
return 1;
}
outFile.open("out.txt");
if(not outFile)
{
cout<<"Failture to open out.txt"<<endl;
system("pause");
return 1;
}

inFile.get(ch);
while(inFile)
{
while((ch!= '\n') and inFile)
{
outFile.put(ch);
inFile.get(ch);
}
if (inFile)
{
outFile.put(ch);
inFile.get(ch);
}
}
system("pause");
inFile.close(); outFile.close();
return 0;

}
```

Is This A Good Question/Topic? 0

## Replies To: Help with converting digits or symbols into numbers

### #2 #define

• Duke of Err

Reputation: 1743
• Posts: 6,202
• Joined: 19-February 09

## Re: Help with converting digits or symbols into numbers

Posted 03 October 2012 - 07:28 PM

You can check for character types cctype

If the character is a digit, print it, ignore commas and periods, otherwise print newline.