0

I am porting a program created in C++ from MS Studio to Ubuntu . The program works fine except when it reads from a text file .

My text file consists of lines of information seperated by the delimiter :

General Manager:G001:def
Customer:C001:def:Lim:Tom:Mr:99999999:zor@hotmail.com:Blk 145 B North #03-03 Singapore 111111

Read method

while (getline(afile,line,'\n')) //read line and store string in variable line
        {


            stringstream ss(line);
            string s;
            while (getline(ss,s,':'))
            {
                word.push_back(s);
            }


            word.clear();

        }

On Windows platform , it is stored correctly as def

However on Ubuntu platform , it is stored as def\\r

It works fine for Customer Record but gives problem for General Manager

I know it has something to do with Carriage return but I am not sure how to resolve it

Computernerd
  • 7,378
  • 18
  • 66
  • 95
  • Look at this question: http://stackoverflow.com/questions/6089231/getting-std-ifstream-to-handle-lf-cr-and-crlf – user1781290 Feb 12 '14 at 04:35

1 Answers1

0

If the text file was created on Windows, you can use the dos2unix command to remove the extra \r's from the file. The command is simply dos2unix filenamegoeshere

user253751
  • 57,427
  • 7
  • 48
  • 90