程式目標:輸入一個字元串,豎向輸出該字元串。使用string和動態分配記憶體機制。代碼如下: #include<iostream>#include "stdafx.h"#include<cstring>int main(){ using namespace std; string s= cin.get ...
程式目標:輸入一個字元串,豎向輸出該字元串。使用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
####希望用一個錯誤來開始我的博客園之旅,只有不停的糾錯,才能提高####