2011-11-07 60 views
2

我不知道为什么我得到错误C2143:语法错误:缺少“;”之前“==” 将不胜感激,如果有人可以解释我的错误。我不断收到一个语法错误,但我不知道为什么

#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; 
}; 
+3

,错误的行号将是最有帮助的。 – KevinDTimm

回答

10

我怀疑问题就在这里:

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

这也许应该是:

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

这条线:

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

应该是:

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

您还没有初始化的 'C' 呢。

的std :: string :: size_type的Ç== 0;

应该是

std :: string :: size_type c = 0;

+1

True(+1),但不需要初始化变量;这只是一个无效的语法结构。 – 2011-11-07 19:59:44

+0

ahhh是的。谢谢! –

0

问题是

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

时,应

std::string::size_type c = 0; 

它需要一个平等的运营商在未来(赋值运算符)

相关问题