c++ - Reading int As Separate Digits -


i have numbers in text file negative, contain decimal, have managed read them , convert them integers display;

    (int = 0; < 1; i++)     {            std::string str = &(cmemblock[0]); //cmemblock .txt file         std::istringstream iss(str);         std::vector<int> numbers;         int number;         while (iss >> number) {             numbers.push_back(number);  // collect inputs              cout << number << endl; //displays stored value             }              if (!iss.eof()) {             cout << "blank space"<<endl; //error message detect blank space         }     } 

i need on creating loop read each each character, example if 1st line '-0.009876', each value should read separately, '-', '0' '.' , on. reason because number represented in morse code, has been set in array, need individual number allocate each digit specified morse code.

based on you've posted, wouldn't bother local numeric conversion. read in text file , iterate across each character individually, mapping morse code mapping array. if need use given number index mapping array, can convert char int value "subtracting" '0' it, eg, assuming loop using charposition outermost loop index through string..

//...omitting other obvious loop code // str holding '-0.009776'  if (isdigit(str[charposition])) {    int index = str[charposition] - '0';    // index 0-based array of presumed morse code mapping values    morsevalue = morsemap[index]; } 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -