2018/3/2晚11点30分写的程序(C++)
程序目标:输入一个字符串,竖向输出该字符串。使用string和动态分配内存机制。代码如下:
#include<iostream>
#include "stdafx.h"
#include<cstring>
int main()
{
using namespace std;
string s= cin.getline;
char * a = new char[sizeof(s)];
for (int m = 0;m < sizeof(s);m++)
a[m] = s[m];
for (int n = 0;n < sizeof(s);n++)
cout << a[n] << endl;
delete[] a;
cin.get();
cin.get();
return 0;
}
编译器:Visual Studio 2015
显示编译错误,但是不知道怎么修改。先记录在这。希望大神不吝赐教。
错误信息:
严重性 代码 说明 项目 文件 行 禁止显示状态
错误 C2146 语法错误: 缺少“;”(在标识符“s”的前面) MyProject_001 c:\users\administrator\documents\visual studio 2015\projects\myproject_01\myproject_001\myproject_001\myproject_001.cpp 10
错误 C2065 “s”: 未声明的标识符 MyProject_001 c:\users\administrator\documents\visual studio 2015\projects\myproject_01\myproject_001\myproject_001\myproject_001.cpp 10
错误 C2065 “cin”: 未声明的标识符 MyProject_001 c:\users\administrator\documents\visual studio 2015\projects\myproject_01\myproject_001\myproject_001\myproject_001.cpp 10
错误 C2228 “.getline”的左边必须有类/结构/联合 MyProject_001 c:\users\administrator\documents\visual studio 2015\projects\myproject_01\myproject_001\myproject_001\myproject_001.cpp 10
错误 C2065 “s”: 未声明的标识符 MyProject_001 c:\users\administrator\documents\visual studio 2015\projects\myproject_01\myproject_001\myproject_001\myproject_001.cpp 11
错误 C2065 “s”: 未声明的标识符 MyProject_001 c:\users\administrator\documents\visual studio 2015\projects\myproject_01\myproject_001\myproject_001\myproject_001.cpp 12
错误 C2065 “s”: 未声明的标识符 MyProject_001 c:\users\administrator\documents\visual studio 2015\projects\myproject_01\myproject_001\myproject_001\myproject_001.cpp 13
错误 C2065 “s”: 未声明的标识符 MyProject_001 c:\users\administrator\documents\visual studio 2015\projects\myproject_01\myproject_001\myproject_001\myproject_001.cpp 14
错误 C2065 “cout”: 未声明的标识符 MyProject_001 c:\users\administrator\documents\visual studio 2015\projects\myproject_01\myproject_001\myproject_001\myproject_001.cpp 15
错误 C2065 “endl”: 未声明的标识符 MyProject_001 c:\users\administrator\documents\visual studio 2015\projects\myproject_01\myproject_001\myproject_001\myproject_001.cpp 15
错误 C2065 “cin”: 未声明的标识符 MyProject_001 c:\users\administrator\documents\visual studio 2015\projects\myproject_01\myproject_001\myproject_001\myproject_001.cpp 17
错误 C2228 “.get”的左边必须有类/结构/联合 MyProject_001 c:\users\administrator\documents\visual studio 2015\projects\myproject_01\myproject_001\myproject_001\myproject_001.cpp 17
错误 C2065 “cin”: 未声明的标识符 MyProject_001 c:\users\administrator\documents\visual studio 2015\projects\myproject_01\myproject_001\myproject_001\myproject_001.cpp 18
错误 C2228 “.get”的左边必须有类/结构/联合 MyProject_001 c:\users\administrator\documents\visual studio 2015\projects\myproject_01\myproject_001\myproject_001\myproject_001.cpp 18
####希望用一个错误来开始我的博客园之旅,只有不停的纠错,才能提高####