本文へスキップ
製品デスクトップツールTASTECAD図面の確認TASTEFILESファイル管理TASTEFTPファイル転送TASTESSHリモートワークスペースTASTEZIP圧縮と展開TASTEWINMファイル管理開発ツールTASTECODERust 統合開発環境TASTESTUDIO統合開発・テスト環境TASTEETLデータ統合(ETL)サーバーTASTEREMOTEリモートデスクトップサーバーTASTEGEO空間情報サーバーTASTEMAILメールワークスペース投資TASTESTOCK株式自動売買デスクトップアプリはじめるダウンロードドキュメント購入すべての製品
マーケットプレイス
ニュース
技術ニュース今日の開発ニュース開発ドキュメントプログラミング言語RustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDartWebフロントエンド フレームワークNext.jsReactVue.js · NuxtSvelteKitAngularサーバー フレームワークSpring BootDjangoFastAPIASP.NET CoreNestJS · Expressアプリ・デスクトップ フレームワークTauriFlutterReact NativeElectronアルゴリズムアルゴリズムの基礎主要アルゴリズム発展アルゴリズム実務のアルゴリズム
コミュニティプロジェクト開発ログプロンプトAIツールの問題ショーケースコミュニティガイド
協業技術移転ウェブサイト構築デスクトップアプリ構築リリース・決済パイプライン販売パートナーお問い合わせ
サービスリモートデスクトップインストールパッケージのカスタマイズ
TASTEDEV
製品

デスクトップツール

TASTECAD複雑な図面を、軽やかにひらくTASTEFILES必要なファイルだけを、最速でTASTEFTPファイルが行き交う、いちばん端正な道TASTESSHサーバーとあなたを、より確かにつなぐTASTEZIPより速くまとめ、より安全にひらくTASTEWINM2つの画面で整理する、キーボード中心のファイルマネージャー

開発ツール

TASTECODERust アプリの編集・ビルド・デバッグ・テストまでひとつのウィンドウでTASTESTUDIO編集からリモートテスト、承認した AI 修正までTASTEETL値を見ながら、データを運ぶ

サーバー

TASTEREMOTE自社サーバーで運用するリモートデスクトップTASTEGEOGeoServer 互換の空間情報サーバーを Rust で作り直しますTASTEMAILメールの主導権を、もう一度自分の手に

投資

TASTESTOCKいつ・何を。自分で決めたルールどおりに動く株式自動売買

はじめる

ダウンロード全製品の最新版ドキュメント各製品の使い方購入サブスクリプション・永久ライセンスすべての製品全製品を一覧で
すべての製品
マーケットプレイスニュース
技術

ニュース

今日の開発ニュース言語・フレームワーク・GitHub・AI の公式発表開発ドキュメント言語・フレームワーク・アルゴリズムのガイド

プログラミング言語

RustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDart

フレームワーク

Webフロントエンド フレームワークNext.jsReactVue.js · NuxtSvelteKitAngular
サーバー フレームワークSpring BootDjangoFastAPIASP.NET CoreNestJS · Express
アプリ・デスクトップ フレームワークTauriFlutterReact NativeElectron

アルゴリズム

アルゴリズムの基礎計算量解析 · ソート · 探索 · 基本データ構造 · 木構造とヒープ主要アルゴリズムグラフ探索 · 最短経路と最小全域木 · 動的計画法 · 貪欲法 · 分割統治法 · バックトラッキング発展アルゴリズム文字列アルゴリズム · 数学と整数論 · ビット演算 · セグメント木 · Union-Find実務のアルゴリズムコーディング面接対策 · LRUキャッシュ · レート制限 · コンシステントハッシュ法
開発ドキュメントをすべて見る
コミュニティ
プロジェクトビルダーと作品を探す開発ログ決定と試行錯誤プロンプト再利用できる指示AIツールの問題Claude・Codex・Gemini の問題と回避策ショーケース完成した成果コミュニティガイドオープンにつくる方法
協業
技術移転Rust・egui でネイティブアプリを作るウェブサイト構築10言語、アカウント、ドキュメントとダウンロードデスクトップアプリ構築Rust・egui、WebView なしリリース・決済パイプライン署名・MSI・deb・rpm・AppImage・ハッシュ販売パートナー紹介して決済額の30%お問い合わせ構築・提携・投資のご相談
サービス
リモートデスクトップブラウザから自分のパソコンへインストールパッケージのカスタマイズ必要な機能だけ、設定は事前に
購入
JA
한국어EnglishDeutschEspañolFrançaisItalianoPortuguês (Brasil)日本語简体中文繁體中文
ログイン
ログイン
TASTEDEV

小さなツールから、より良い開発へ。

support@tastedev.netTASTEDEVを支援
製品製品ラインナップ購入ドキュメントダウンロードマーケットプレイスサポート
コミュニティプロジェクト開発ログプロンプトAIツールの問題ショーケース
ポリシー会社概要プライバシーポリシー利用規約サブスクリプション規約返金ポリシーコミュニティガイドライン
アカウントログイン新規登録
訪問者
今日
昨日
累計閲覧
商号
GXSOFT
代表者
CHOI YOUNG GU
事業者登録番号
853-44-00368
所在地
9F V24, 351 Gyeongin-ro, Michuhol-gu, Incheon, Republic of Korea
電話
+82-10-4404-1523
メール
whitecalvin@tastedev.net
個人情報保護責任者
CHOI YOUNG GU

© 2026 TASTEDEV製品情報は検証済みの開発ソースに基づいています。リリース・改善中

C++ ドキュメント
C++
Getting StartedSyntax BasicsTypes and DataModules and PackagesErrors and TestingKey Concepts
ディスカッション

C++ ガイド · 2/6

Syntax Basics

この章は現在、英語でのみ提供しています。

This chapter covers the building blocks you will use in every C++ program: the main function, variables and auto, references, functions and overloading, control flow, and printing output.

main and statements

Every C++ program starts in main. Statements end with a semicolon, blocks are wrapped in braces, and comments come in two flavors: // for a single line and /* ... */ for a span.

#include <iostream>

int main(int argc, char* argv[]) {
    // argc: number of arguments, argv: the arguments as C strings
    std::cout << argc << " argument(s), program: " << argv[0] << '\n';
    return 0; // optional in main: falling off the end returns 0
}

Variables and auto

A variable is declared with a type and a name. Brace initialization ({}) is worth making a habit, because the compiler rejects narrowing conversions that would silently lose data. auto deduces the type from the initializer, and const makes a value read-only.

#include <string>

int count{10};
double ratio = 0.75;
const int max_users{100};   // cannot be modified
constexpr int buffer = 256; // value known at compile time

auto name = std::string{"Kim"}; // std::string
auto total = count * 2;         // int

// int bad{3.14};  // error: narrowing from double to int

An uninitialized local variable holds an indeterminate value, and reading it is a bug. Give every variable an initial value when you declare it.

References

A reference (&) is an alias for an existing object. References are the usual way to pass large objects to functions without copying them. If the function only reads the argument, take it by const reference.

#include <string>

void add_suffix(std::string& text) {             // modifies the caller's string
    text += "!";
}

std::size_t length_of(const std::string& text) { // read-only, no copy
    return text.size();
}

int main() {
    std::string greeting{"hello"};
    add_suffix(greeting);          // greeting is now "hello!"
    auto n = length_of(greeting);  // 6
    int value = 1;
    int& alias = value;
    alias = 5;                     // value is 5 too
}

A reference must be bound when it is declared and can never be reseated to refer to something else. When you need something that can change targets or be empty, use a pointer.

Functions and overloading

A function has a return type, a name and a parameter list. Several functions can share a name as long as their parameter lists differ; this is called overloading. Parameters can also have default values.

#include <string>

int area(int w, int h) { return w * h; }
double area(double radius) { return 3.14159 * radius * radius; }

std::string repeat(const std::string& s, int times = 2) {
    std::string out;
    for (int i = 0; i < times; ++i) out += s;
    return out;
}

// area(3, 4)  -> 12
// area(1.5)   -> area of a circle
// repeat("ab") -> "abab", repeat("ab", 3) -> "ababab"
この章について質問がありますか?
前の章Getting Started次の章Types and Data

The compiler picks an overload by matching the argument types at the call site. If two candidates are equally good, the call is ambiguous and won't compile.

Control flow

if, switch, while and the classic for loop look much like they do in C. Since C++11 there is also the range-based for, which visits every element of a container, and since C++17 if can declare a variable right in its header.

#include <iostream>
#include <vector>

int main() {
    std::vector<int> scores{90, 72, 85, 60};

    for (int s : scores) {               // each element by value
        std::cout << s << ' ';
    }
    for (auto& s : scores) {             // by reference, so we can modify
        s += 5;
    }
    for (const auto& s : scores) {       // read-only access
        if (s >= 90) std::cout << "A ";
        else if (s >= 80) std::cout << "B ";
        else std::cout << "C ";
    }

    if (auto n = scores.size(); n > 3) { // C++17 if with initializer
        std::cout << "\n" << n << " scores\n";
    }

    int i = 0;
    while (i < 3) { ++i; }
}

Output: iostream and std::format

std::cout works with every standard version. C++20 added std::format in <format>, which builds a string from a format string with {} placeholders, and C++23 added std::print in <print> to write formatted output directly. Standard library implementations shipped these at different times, so an older toolchain may not have them yet.

#include <format>
#include <iostream>
#include <string>

int main() {
    std::string name{"Lee"};
    int score = 92;
    std::cout << std::format("{} scored {} points.\n", name, score);
    std::cout << std::format("{:>8.2f}|\n", 3.14159); // width 8, 2 decimals
}

If std::format isn't available to you, keep using std::cout, or use the open-source {fmt} library, which the standard facility was based on.

Summary

  • Execution starts in main, and statements end with ;.
  • Prefer brace initialization, use auto for type deduction, and const or constexpr for values that never change.
  • Pass by reference to avoid copies, and by const reference when you only read.
  • Functions with different parameter lists can share a name.
  • Use range-based for to walk containers, and std::format for formatted text when your toolchain supports it.

コメント 0件

人気のコメント順新しい順

ログイン · ログインするとコメントできます。