CPPPROGLIB Telegram 6126
🦀 Транспиляция кода: от одного языка к другому

Представьте ситуацию: вы нашли идеальное решение на GitHub, но оно написано не на том языке. Или ваш руководитель прочитал статью о новом фреймворке, и теперь нужно переписывать всю кодовую базу. Знакомо?

Хорошая новость: современные LLM-модели отлично справляются с транспиляцией кода между языками программирования.


✏️ Промпт

Rewrite the following code in C++:

[Вставь свой код сюда]



🍴 Пример использования

# Исходный Python код

def count_words(text):
"""Count word frequency in text"""
words = text.lower().split()
freq = {}
for word in words:
freq[word] = freq.get(word, 0) + 1
return freq

# Пример использования
text = "hello world hello python world"
print(count_words(text))
# Output: {'hello': 2, 'world': 2, 'python': 1}


Результат:

#include <iostream>
#include <string>
#include <map>
#include <sstream>
#include <algorithm>

std::map<std::string, int> count_words(const std::string& text) {
std::map<std::string, int> freq;
std::istringstream stream(text);
std::string word;

while (stream >> word) {
// Convert to lowercase
std::transform(word.begin(), word.end(), word.begin(), ::tolower);
freq[word]++;
}

return freq;
}

int main() {
std::string text = "hello world hello python world";
auto result = count_words(text);

for (const auto& [word, count] : result) {
std::cout << word << ": " << count << std::endl;
}

return 0;
}


Библиотека C/C++ разработчика


#буст
Please open Telegram to view this post
VIEW IN TELEGRAM
👍9👾1



tgoop.com/cppproglib/6126
Create:
Last Update:

🦀 Транспиляция кода: от одного языка к другому

Представьте ситуацию: вы нашли идеальное решение на GitHub, но оно написано не на том языке. Или ваш руководитель прочитал статью о новом фреймворке, и теперь нужно переписывать всю кодовую базу. Знакомо?

Хорошая новость: современные LLM-модели отлично справляются с транспиляцией кода между языками программирования.


✏️ Промпт

Rewrite the following code in C++:

[Вставь свой код сюда]



🍴 Пример использования

# Исходный Python код

def count_words(text):
"""Count word frequency in text"""
words = text.lower().split()
freq = {}
for word in words:
freq[word] = freq.get(word, 0) + 1
return freq

# Пример использования
text = "hello world hello python world"
print(count_words(text))
# Output: {'hello': 2, 'world': 2, 'python': 1}


Результат:

#include <iostream>
#include <string>
#include <map>
#include <sstream>
#include <algorithm>

std::map<std::string, int> count_words(const std::string& text) {
std::map<std::string, int> freq;
std::istringstream stream(text);
std::string word;

while (stream >> word) {
// Convert to lowercase
std::transform(word.begin(), word.end(), word.begin(), ::tolower);
freq[word]++;
}

return freq;
}

int main() {
std::string text = "hello world hello python world";
auto result = count_words(text);

for (const auto& [word, count] : result) {
std::cout << word << ": " << count << std::endl;
}

return 0;
}


Библиотека C/C++ разработчика


#буст

BY Библиотека C/C++ разработчика | cpp, boost, qt


Share with your friend now:
tgoop.com/cppproglib/6126

View MORE
Open in Telegram


Telegram News

Date: |

Deputy District Judge Peter Hui sentenced computer technician Ng Man-ho on Thursday, a month after the 27-year-old, who ran a Telegram group called SUCK Channel, was found guilty of seven charges of conspiring to incite others to commit illegal acts during the 2019 extradition bill protests and subsequent months. In the “Bear Market Screaming Therapy Group” on Telegram, members are only allowed to post voice notes of themselves screaming. Anything else will result in an instant ban from the group, which currently has about 75 members. "Doxxing content is forbidden on Telegram and our moderators routinely remove such content from around the world," said a spokesman for the messaging app, Remi Vaughn. How to create a business channel on Telegram? (Tutorial) ZDNET RECOMMENDS
from us


Telegram Библиотека C/C++ разработчика | cpp, boost, qt
FROM American