История изменений
Исправление Sahas, (текущая версия) :
cat test.cpp
#include <iostream>
#include <string>
int main() {
std::string s = "Hello, world!\n";
std::cout << s;
}
g++ test.cpp
./a.out
Hello, world!
sed -i 's/world/Vasya/' a.out
./a.out
Hello, Vasya!
-O2 компиляция всё оптимизирует, поэтому с ней такой фокус не прокатывает
update: static std::string s = «Hello, world!\n» работает и в случае -O2
Исправление Sahas, :
cat test.cpp
#include <iostream>
#include <string>
int main() {
std::string s = "Hello, world!\n";
std::cout << s;
}
g++ test.cpp
./a.out
Hello, world!
sed -i 's/world/Vasya/' a.out
./a.out
Hello, Vasya!
-O2 компиляция всё оптимизирует, поэтому с ней такой фокус не прокатывает
Исходная версия Sahas, :
cat test.cpp
#include <iostream>
#include <string>
int main() {
std::string s = "Hello, world!\n";
std::cout << s;
}
g++ test.cpp
./a.out
Hello, world!
sed -i 's/world/Vasya/' a.out
./a.out
Hello, Vasya!