C++ string.substr compiles differently
Clash 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?
x11 c++ g++
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.
add a comment |Â
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?
x11 c++ g++
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 byCR
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
add a comment |Â
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?
x11 c++ g++
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++
x11 c++ g++
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 byCR
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
add a comment |Â
1
Do you byCR
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
add a comment |Â
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
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
add a comment |Â
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
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
add a comment |Â
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
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
add a comment |Â
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
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
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
add a comment |Â
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
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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