value2.cpp

This program reads a double floating-point value followed by a single suffix character from a null-terminated string. The strings are obtained from command line arguments.

This version uses iostreams.


#include <iostream>
#include <sstream>
#include <stdlib.h>
using namespace std;

int main(int argc, char *argv[])
{
	int i;
	double v;
	char c;
	for (i=1; i<argc; i++) {
		istringstream is(argv[i]);
		is >> v >> c;
		if (is.eof()) c = '?';
		//sscanf_s(argv[i],"%Le%c",&v,&c);
		//printf("%s: %g %c\n",argv[i],v,c);
		cout << argv[i] << ": " << v << " " << c << endl;
	}
	return EXIT_SUCCESS;
}


Results

C:\classes\ece538\work\netlist1>value2 0.4ns 10MEG 15 1G 3m
0.4ns: 0.4 n
10MEG: 10 M
15: 15 ?
1G: 1 G
3m: 3 m


Maintained by John Loomis, updated Sun Jan 07 19:23:07 2007