Jump to content
  • Advertisement
Sign in to follow this  
NightStalker

Small Problem

This topic is 4718 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm having a problem with a function that I am writing. It scans through a string finding and replacing certain words with a designated symbol. Here's the code and the main test code:
#include <string>
#include <iostream>
#include <fstream>
using namespace std;

bool DMS(string &input)
{
   int position;
   string degrees = " \0xf8";
   string minutes = " \"";
   string seconds = " '";
   const string degreeList[4] = 
   { " DEGREES", " DEGREE", "DEGREES", "DEGREE"};
   const string minuteList[4] = 
   { " MINUTES", " MINUTE", "MINUTES", "MINUTE"};
   const string secondList[4] = 
   { " SECONDS", " SECOND", "SECONDS", "SECOND"};
   // Find and replace DEGREES
   for(int i = 0; i < 4; ++i)
   {
      position = input.find(degreeList);
      while(position != string::npos)
      {
         input.replace(position, degreeList.length(), degrees);
         position = input.find(degreeList, position + 1);
      }      
   }
   // Find and replace MINUTES
   for(int i = 0; i < 4; ++i)
   {
      position = input.find(minuteList);
      while(position != string::npos)
      {
         input.replace(position, minuteList.length(), minutes);
         position = input.find(minuteList, position + 1);
      }      
   }
   // Find and replace SECONDS
   for(int i = 0; i < 4; ++i)
   {
      position = input.find(secondList);
      while(position != string::npos)
      {
         input.replace(position, secondList.length(), seconds);
         position = input.find(secondList, position + 1);
      }      
   }
}

int main()
{
   ofstream fout;
   fout.open("C:\\Test.txt");
   string a = "DEGREE MINUTESSECONDS MINUTE DEGREES";
   fout << a << endl;
   DMS(a);
   fout << a;
   cin.get();
   fout.close();
   return 0;
}


It's not printing the degree sign for the degrees. Could someone plz tell me what i am doing wrong?

Share this post


Link to post
Share on other sites
Advertisement
That's because you're sending "\0xf8", which is a four character string that starts with null terminator - in other words, it may as well be a blank string.

You could just do:

string degrees = "°";

or if that doesn't work, (might not due to different charsets) something like:

string degrees = " ";
degrees[0] = 0xf8;

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!