不确定出了什么问题(字符串输入)
Not sure whats going wrong (string input)
为 class 编写程序,我们使用函数从输入 txt 文件复制数据列表。我的功能之一是获取他们想要搜索数据的文件名的输入。这是我的文件的预处理器说明以及功能代码,但是在 .getline 上,我在 .getline 行上不断收到相同的错误,我不确定如何解决这个问题。还想知道我的代码的一般流程是否有意义。谢谢!
#include <iostream>
#include <iomanip>
#include <string>
#include <time.h>
#include <stdlib.h>
#include <fstream>
using namespace std;
const char PROGRAMMER[29] = "Matt Napoli & Jeff Koucoulis";
const char CLASS[5] = "CS1A";
const char SECTION[25] = "MW: Mon/Wed 5-7:20 PM";
const int LAB_NUM = 13;
const char LAB_NAME[17] = "Arrays in C++";
string input;
const int AR_SIZE = 10;
string checkFile()
{
cout << "What input file would you like to use? ";
cin.getline(cin, input);
return input;
}
void filetoArray()
{
cout << "Reading records from input file " << input;
cout << "Who do you want to search for (enter done to exit)? " << endl;
ifstream file(input);
if(file.is_open())
{
string whatsInFile[AR_SIZE];
for(int i = 0; i < AR_SIZE; ++i)
{
file >> whatsInFile[AR_SIZE];
}
}
}
还有我的main.cpp文件
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <time.h>
#include <stdlib.h>
#include <fstream>
using namespace std;
string input;
string inFile();
const int AR_SIZE = 10;
string whatsInFile[AR_SIZE];
int main() {
int index = 0;
void InFile();
while (inFile && index < AR_SIZE)
{
void filetoArray();
}
return 0;
}
我的输入文件在这里
Joe
Sally
Joe
Sue
Sally
Adam
Joe
Adam
Adam
Joe
简单的怎么样:
std::getline(cin, input);
而不是
cin.getline(cin, input);
这是错误的,因为 std::basic_istream<CharT,Traits>::getline
的签名是:
basic_istream& getline( char_type* s, std::streamsize count );
为 class 编写程序,我们使用函数从输入 txt 文件复制数据列表。我的功能之一是获取他们想要搜索数据的文件名的输入。这是我的文件的预处理器说明以及功能代码,但是在 .getline 上,我在 .getline 行上不断收到相同的错误,我不确定如何解决这个问题。还想知道我的代码的一般流程是否有意义。谢谢!
#include <iostream>
#include <iomanip>
#include <string>
#include <time.h>
#include <stdlib.h>
#include <fstream>
using namespace std;
const char PROGRAMMER[29] = "Matt Napoli & Jeff Koucoulis";
const char CLASS[5] = "CS1A";
const char SECTION[25] = "MW: Mon/Wed 5-7:20 PM";
const int LAB_NUM = 13;
const char LAB_NAME[17] = "Arrays in C++";
string input;
const int AR_SIZE = 10;
string checkFile()
{
cout << "What input file would you like to use? ";
cin.getline(cin, input);
return input;
}
void filetoArray()
{
cout << "Reading records from input file " << input;
cout << "Who do you want to search for (enter done to exit)? " << endl;
ifstream file(input);
if(file.is_open())
{
string whatsInFile[AR_SIZE];
for(int i = 0; i < AR_SIZE; ++i)
{
file >> whatsInFile[AR_SIZE];
}
}
}
还有我的main.cpp文件
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <time.h>
#include <stdlib.h>
#include <fstream>
using namespace std;
string input;
string inFile();
const int AR_SIZE = 10;
string whatsInFile[AR_SIZE];
int main() {
int index = 0;
void InFile();
while (inFile && index < AR_SIZE)
{
void filetoArray();
}
return 0;
}
我的输入文件在这里
Joe
Sally
Joe
Sue
Sally
Adam
Joe
Adam
Adam
Joe
简单的怎么样:
std::getline(cin, input);
而不是
cin.getline(cin, input);
这是错误的,因为 std::basic_istream<CharT,Traits>::getline
的签名是:
basic_istream& getline( char_type* s, std::streamsize count );