Help with strings

Im learning to use strings and I made a code using them, but im getting errors at lines 8, 9 and 10

Line 8: no match for call to '(std::string {aka std::basic_string<char>}) (const char [5])'|
Line 8: expected '}' before ';' token|
Line 9:'run' does not name a type|
Line 10: expected unqualified-id before 'while'|

What im doing wrong?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include<iostream>
using namespace std;

string commands;
int run;

int main {
    commands ("none");
    run = 1;
    while (run == 1) {
        cout << "Enter a command";
        cin >> commands;
        if (commands == "ping") {
            cout << "pong";
            commands ("none");
        }
    }
}
Declare main() as a function:

int main()

Change to:

commands = "none";

on lines 8 and 15
Hi all,
after making changes that machinafour said, include string header File.
#include <string.h> OR #include <cstring>

EDIT: edited to correct my mistakes.
Last edited on
you should include C++ string header file. It is #include <string> Your code might work without including it but it is not guaranteed.
Topic archived. No new replies allowed.