简体   繁体   English

我一直收到语法错误,但我不确定原因

[英]I keep getting a syntax error but I am not sure why

I am not sure why I get the error C2143: syntax error : missing ';' 我不知道为什么我得到错误C2143:语法错误:缺少';' before '==' Would be most grateful if somebody would explain my error. 在'==之前如果有人会解释我的错误,我将不胜感激。

#include <iostream>
#include <string>
#include <cstdlib>

int main() {

std::cout << "What is your name? ";
std::string name;
std::cin >> name;
const std::string greeting = "Hello " + name + " !";
//
const int pad = 1;
const int rows = pad * 2 + 3;
std::cout << std::endl;
//
int r = 0;
while (r != rows) {
    std::cout << std::endl;
    ++r;
}
//
std::string::size_type cols = greeting.size() + pad * 2 + 2;
std::string::size_type c == 0;
while (c != cols) {
    if (r == 0 || r == rows -1 || c == 0 || c == cols -1) {
    } else {
    }
}

std::system("pause");

return 0;
};

I suspect the problem is here: 我怀疑问题在这里:

std::string::size_type c == 0;

That should probably be: 这应该是:

std::string::size_type c = 0;

This line: 这一行:

std::string::size_type c == 0;

should be: 应该:

std::string::size_type c = 0;

You have not initialized 'c' yet. 你还没有初始化'c'。

std::string::size_type c == 0; std :: string :: size_type c == 0;

should be 应该

std::string::size_type c = 0; std :: string :: size_type c = 0;

problem is 问题是

std::string::size_type c == 0; 

when should be 应该什么时候

std::string::size_type c = 0;

it needs to be single equal operator(assignment operator) 它需要是单个相等的运算符(赋值运算符)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM