你好:)我正在尝试为我的Intro to Programming类开发一个项目,我遇到了一个问题,其中intellisense(错误地?)读取我使用getline作为重载函数。这可能是我自己的错,但我想把它带到这里作为解释,如果这是我做过的事情。
项目要求我打开文件:
// Local variables
int position = 0;
// Open column1.txt
ifstream column1;
column1.open("column1.txt");
现在该文件已打开,必须将内容读入数组(字符串COLUMN1 [50]在代码开头声明为全局变量):
// Copy its contents into the first array
if (column1.is_open())
{
while (!column1.eof() && position < 50)
{
COLUMN1[position] = getline(column1, position, '/n');
position++;
}
}
就是这样。我将在下面提供整个代码以供参考。任何帮助表示赞赏!谢谢!
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
// Funtion Prototypes
void copyCat(); // File that copies the info to the arrays
// Global Constants
const string COLUMN1[50]; // Each of the columns of
const string COLUMN2[50]; // insults. Each column is
const string COLUMN3[50]; // located in a different file.
// ---------------------------------------------
// Name: Main
// Purpose: Houses the program's main process
// Returns: int 0
// ---------------------------------------------
int main()
{
copyCat();
system("pause");
return 0;
}
// -----------------------------------------
// Name: copyCat
// Purpose: Copies the files into the arrays
// Returns: void
// -----------------------------------------
void copyCat()
{
// Local Variables
int position = 0;
// Open column1.txt and copy it into the array
ifstream column1;
column1.open("column1.txt");
// Copy its contents into the first array
if (column1.is_open())
{
while (!column1.eof() && position < 50)
{
COLUMN1[position] = getline(column1, position, '/n');
position++;
}
}
}