【发布时间】:2014-01-16 04:16:58
【问题描述】:
只要我注释掉 cin.get 行,我的代码似乎就可以编译,但我看不出我是如何滥用它的。作为第二个问题,一旦我弄清楚我在那里做错了什么,我是否可以使用 getlength 来计算该字符串的长度,然后使用 prtintf 将该长度的 cstring 打印到我的输出文件中计划加入?顺便说一句,我不允许使用字符串。
#include<iostream>
#include<fstream>
#include<cstring>
#include<string>
using namespace std;
struct thisType
{
char peiceOne[100];
char peiceTwo[100];
char peiceThree[100];
};
void requestData();
void storeData(char *charArray[]);
int main(){
thisType tempStruct[100];
requestData();
return 0;
}
void requestData(){
cout << endl << "Please enter data as follows, without brackets: [peiceOne];"
<< "[peiceTwo];[peiceThree] " << endl;
}
void storeData(char *tempStruct[100]){
//cin.get(tempStruct[0], 100, ";");
}
【问题讨论】:
-
请考虑使用
std::string和提取运算符operator>>在c++ 中读取std::istream。 -
这是一个类,我不能使用字符串,但我可以使用 cstrings。
-
那你为什么要包含
<string>?对于您的代码,仅需要<iostream>。 C 字符串不需要“包含”它们是内置类型。<cstring>包含你只需要进行字符串操作的东西。 -
我不知道,我会摆脱它。
-
你到底想做什么?你的任务是什么?
标签: c++ arrays get char typedef