请求分号时出现令人困惑的错误(错误 C2143)
Confusing error requesting semicolon (error C2143)
我正在使用VS Professional 2013,我正在构建一个控制台应用程序。我的一种方法是根据用户输入确定字符串长度。我在此方法的第 5 行不断收到一个令人困惑的错误:缺少分号(错误 C2143)。据我所知,行内的任何函数都不需要额外的分号。另外,我故意不调用命名空间。下面复制了 #include 函数,并存储在头文件中。
#include <stdio.h>
#include <tchar.h> //Part of VS' implementation for applications. Can effectively be ignored.
#include <iostream>
#include <string>
int main() {
std::string s;
std::cout << "Enter your string: " << std::flush;
std::string.getline(std::cin, s);
const int size = s.length();
std::cout << "The total number of characters entered is: " << size << std::endl;
}
std::string
没有成员getline
,所以std::string.getline(std::cin, s);
是非法的。
你想要
std::getline(std::cin, s);
相关文章:
- 为什么我会收到错误 C2143 语法错误:缺少"*"之前的';'?
- 错误 C2143:语法错误:':'之前缺少','
- 编译错误 C2143:语法错误:'<'之前缺少';'
- 错误 C2143:语法错误:'<' C++之前缺少';'
- 错误 C2143:语法错误:在"*"之前缺少"{"
- 请求分号时出现令人困惑的错误(错误 C2143)
- 两个语法错误:错误 C2143 语法错误:'*'之前缺少';'
- 可变参数模板 - 错误 C2143:语法错误:'...'之前缺少','
- 错误 C2143:语法错误:':'之前缺少';'
- CS106b 库矢量.cpp错误 C2143:语法错误:'<'之前缺少';'
- 模板类引发错误 C2143:语法错误:在"<"之前缺少";"
- C++ 结构 - 错误 1 错误 C2143:语法错误:缺少'*'之前的';'
- 错误 C4430:AND 错误 C2143:语法错误:'*'之前缺少';'
- 错误 C2143:语法错误:声明指针时'*'之前缺少';'
- afxtempl.h 错误 12 错误 C2143:语法错误:缺少'}'之前的';'
- C++:错误 C2143:语法错误:'<'之前缺少';'
- 错误 C2143:语法错误:命名空间之前缺少";"
- 错误 C2143:语法错误:'if'之前缺少';'
- 错误 C2143:语法错误:在"__stdcall"之前缺少";"
- 在函数定义中指定参数默认值会导致错误 C2143:语法错误:'='之前缺少')'