C++ string.substr compiles differently

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












I have two pairs of files. The source files are identical copies apart from the path to the identical text files they interrogate.
One pair runs on Linux Cinnamon 18.x the other on Raspbian Stretch. Each pair is compiled on its own platform.



std::string sTemp = ImportDS18B20("testy.txt");

if (sTemp.find("YES") != std::string::npos)
size_t p = sTemp.find("t= ");

if (p != std::string::npos) " << sFloor << "

break;



The code produces 5 |19555| on Raspbian and 6 |19555n| on Cinnamon. (n is of course just to represent a CR on this site.)
I assume this is a C++ compiler issue. Is that correct? How do I make the code portable?










share|improve this question













migrated from unix.stackexchange.com Aug 15 at 15:44


This question came from our site for users of Linux, FreeBSD and other Un*x-like operating systems.










  • 1




    Do you by CR mean a carriage return (r)? Are the two files on the two machines identical, or is the Cinnamon file a DOS text file?
    – Kusalananda
    Aug 15 at 9:23










  • I did mean to replicate the effect of a new line as this is how cout displays it. More accurately I think substr() in Cinnamon is picking up the EOL char since there are no other printable chars in the file (and there is no "r" or "n" in the file). Both pairs of files are identical as stated - they are both copies made and saved in the Cinnamon box straight to the SD card holding the Raspbian. Both compiled by g++ c11 btw.
    – Hillybilly
    Aug 15 at 17:53














up vote
0
down vote

favorite












I have two pairs of files. The source files are identical copies apart from the path to the identical text files they interrogate.
One pair runs on Linux Cinnamon 18.x the other on Raspbian Stretch. Each pair is compiled on its own platform.



std::string sTemp = ImportDS18B20("testy.txt");

if (sTemp.find("YES") != std::string::npos)
size_t p = sTemp.find("t= ");

if (p != std::string::npos) " << sFloor << "

break;



The code produces 5 |19555| on Raspbian and 6 |19555n| on Cinnamon. (n is of course just to represent a CR on this site.)
I assume this is a C++ compiler issue. Is that correct? How do I make the code portable?










share|improve this question













migrated from unix.stackexchange.com Aug 15 at 15:44


This question came from our site for users of Linux, FreeBSD and other Un*x-like operating systems.










  • 1




    Do you by CR mean a carriage return (r)? Are the two files on the two machines identical, or is the Cinnamon file a DOS text file?
    – Kusalananda
    Aug 15 at 9:23










  • I did mean to replicate the effect of a new line as this is how cout displays it. More accurately I think substr() in Cinnamon is picking up the EOL char since there are no other printable chars in the file (and there is no "r" or "n" in the file). Both pairs of files are identical as stated - they are both copies made and saved in the Cinnamon box straight to the SD card holding the Raspbian. Both compiled by g++ c11 btw.
    – Hillybilly
    Aug 15 at 17:53












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have two pairs of files. The source files are identical copies apart from the path to the identical text files they interrogate.
One pair runs on Linux Cinnamon 18.x the other on Raspbian Stretch. Each pair is compiled on its own platform.



std::string sTemp = ImportDS18B20("testy.txt");

if (sTemp.find("YES") != std::string::npos)
size_t p = sTemp.find("t= ");

if (p != std::string::npos) " << sFloor << "

break;



The code produces 5 |19555| on Raspbian and 6 |19555n| on Cinnamon. (n is of course just to represent a CR on this site.)
I assume this is a C++ compiler issue. Is that correct? How do I make the code portable?










share|improve this question













I have two pairs of files. The source files are identical copies apart from the path to the identical text files they interrogate.
One pair runs on Linux Cinnamon 18.x the other on Raspbian Stretch. Each pair is compiled on its own platform.



std::string sTemp = ImportDS18B20("testy.txt");

if (sTemp.find("YES") != std::string::npos)
size_t p = sTemp.find("t= ");

if (p != std::string::npos) " << sFloor << "

break;



The code produces 5 |19555| on Raspbian and 6 |19555n| on Cinnamon. (n is of course just to represent a CR on this site.)
I assume this is a C++ compiler issue. Is that correct? How do I make the code portable?







x11 c++ g++






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Aug 15 at 8:32









Hillybilly

51




51




migrated from unix.stackexchange.com Aug 15 at 15:44


This question came from our site for users of Linux, FreeBSD and other Un*x-like operating systems.






migrated from unix.stackexchange.com Aug 15 at 15:44


This question came from our site for users of Linux, FreeBSD and other Un*x-like operating systems.









  • 1




    Do you by CR mean a carriage return (r)? Are the two files on the two machines identical, or is the Cinnamon file a DOS text file?
    – Kusalananda
    Aug 15 at 9:23










  • I did mean to replicate the effect of a new line as this is how cout displays it. More accurately I think substr() in Cinnamon is picking up the EOL char since there are no other printable chars in the file (and there is no "r" or "n" in the file). Both pairs of files are identical as stated - they are both copies made and saved in the Cinnamon box straight to the SD card holding the Raspbian. Both compiled by g++ c11 btw.
    – Hillybilly
    Aug 15 at 17:53












  • 1




    Do you by CR mean a carriage return (r)? Are the two files on the two machines identical, or is the Cinnamon file a DOS text file?
    – Kusalananda
    Aug 15 at 9:23










  • I did mean to replicate the effect of a new line as this is how cout displays it. More accurately I think substr() in Cinnamon is picking up the EOL char since there are no other printable chars in the file (and there is no "r" or "n" in the file). Both pairs of files are identical as stated - they are both copies made and saved in the Cinnamon box straight to the SD card holding the Raspbian. Both compiled by g++ c11 btw.
    – Hillybilly
    Aug 15 at 17:53







1




1




Do you by CR mean a carriage return (r)? Are the two files on the two machines identical, or is the Cinnamon file a DOS text file?
– Kusalananda
Aug 15 at 9:23




Do you by CR mean a carriage return (r)? Are the two files on the two machines identical, or is the Cinnamon file a DOS text file?
– Kusalananda
Aug 15 at 9:23












I did mean to replicate the effect of a new line as this is how cout displays it. More accurately I think substr() in Cinnamon is picking up the EOL char since there are no other printable chars in the file (and there is no "r" or "n" in the file). Both pairs of files are identical as stated - they are both copies made and saved in the Cinnamon box straight to the SD card holding the Raspbian. Both compiled by g++ c11 btw.
– Hillybilly
Aug 15 at 17:53




I did mean to replicate the effect of a new line as this is how cout displays it. More accurately I think substr() in Cinnamon is picking up the EOL char since there are no other printable chars in the file (and there is no "r" or "n" in the file). Both pairs of files are identical as stated - they are both copies made and saved in the Cinnamon box straight to the SD card holding the Raspbian. Both compiled by g++ c11 btw.
– Hillybilly
Aug 15 at 17:53












1 Answer
1






active

oldest

votes

















up vote
0
down vote



accepted










I suspect that your issue is with the ImportDS18B20() function rather than the code you've posted or the compiler. To verify that the files are identical, check the length and md5sum.



I would strip trailing r (and n to make it cross-platform)



sFloor = sTemp.substr(p);

while (sTemp.back() == 'r' || sTemp.back() == 'n')
sTemp.pop_back();

uint uTemp = sFloor.length();


Mike






share|improve this answer




















  • tks for back() - worked. md5's good. Import DS18B20 identical in same cpp's. So I still don't see what was different but no matter with your solution
    – Hillybilly
    Aug 16 at 9:03










Your Answer





StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f51862025%2fc-string-substr-compiles-differently%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote



accepted










I suspect that your issue is with the ImportDS18B20() function rather than the code you've posted or the compiler. To verify that the files are identical, check the length and md5sum.



I would strip trailing r (and n to make it cross-platform)



sFloor = sTemp.substr(p);

while (sTemp.back() == 'r' || sTemp.back() == 'n')
sTemp.pop_back();

uint uTemp = sFloor.length();


Mike






share|improve this answer




















  • tks for back() - worked. md5's good. Import DS18B20 identical in same cpp's. So I still don't see what was different but no matter with your solution
    – Hillybilly
    Aug 16 at 9:03














up vote
0
down vote



accepted










I suspect that your issue is with the ImportDS18B20() function rather than the code you've posted or the compiler. To verify that the files are identical, check the length and md5sum.



I would strip trailing r (and n to make it cross-platform)



sFloor = sTemp.substr(p);

while (sTemp.back() == 'r' || sTemp.back() == 'n')
sTemp.pop_back();

uint uTemp = sFloor.length();


Mike






share|improve this answer




















  • tks for back() - worked. md5's good. Import DS18B20 identical in same cpp's. So I still don't see what was different but no matter with your solution
    – Hillybilly
    Aug 16 at 9:03












up vote
0
down vote



accepted







up vote
0
down vote



accepted






I suspect that your issue is with the ImportDS18B20() function rather than the code you've posted or the compiler. To verify that the files are identical, check the length and md5sum.



I would strip trailing r (and n to make it cross-platform)



sFloor = sTemp.substr(p);

while (sTemp.back() == 'r' || sTemp.back() == 'n')
sTemp.pop_back();

uint uTemp = sFloor.length();


Mike






share|improve this answer












I suspect that your issue is with the ImportDS18B20() function rather than the code you've posted or the compiler. To verify that the files are identical, check the length and md5sum.



I would strip trailing r (and n to make it cross-platform)



sFloor = sTemp.substr(p);

while (sTemp.back() == 'r' || sTemp.back() == 'n')
sTemp.pop_back();

uint uTemp = sFloor.length();


Mike







share|improve this answer












share|improve this answer



share|improve this answer










answered Aug 15 at 22:55









Michael Surette

1469




1469











  • tks for back() - worked. md5's good. Import DS18B20 identical in same cpp's. So I still don't see what was different but no matter with your solution
    – Hillybilly
    Aug 16 at 9:03
















  • tks for back() - worked. md5's good. Import DS18B20 identical in same cpp's. So I still don't see what was different but no matter with your solution
    – Hillybilly
    Aug 16 at 9:03















tks for back() - worked. md5's good. Import DS18B20 identical in same cpp's. So I still don't see what was different but no matter with your solution
– Hillybilly
Aug 16 at 9:03




tks for back() - worked. md5's good. Import DS18B20 identical in same cpp's. So I still don't see what was different but no matter with your solution
– Hillybilly
Aug 16 at 9:03

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f51862025%2fc-string-substr-compiles-differently%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay