Help With Converting Digits Or Symbols Into Numbers
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:
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 29 30 31 32 33 34 35 36 37 38 39 40
|
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;
}
|
Last edited on
Topic archived. No new replies allowed.