C++ 读取单词并将其存储到数组中
因此,我目前有一个工作程序,可以成功地找到并显示文本文件中的所有字符。我现在想能够阅读整个单词而不是字符,然后想将每个单词存储到一个数组中,但我甚至不知道如何阅读整个单词 我当前的字符代码C++ 读取单词并将其存储到数组中,c++,C++,因此,我目前有一个工作程序,可以成功地找到并显示文本文件中的所有字符。我现在想能够阅读整个单词而不是字符,然后想将每个单词存储到一个数组中,但我甚至不知道如何阅读整个单词 我当前的字符代码 #include <iostream> #include <fstream> using namespace std; int main() { ifstream infile("input.txt"); if (!infile) { cou
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream infile("input.txt");
if (!infile)
{
cout << "ERROR: ";
cout << "Can't open input file\n";
}
infile >> noskipws;
while (!infile.eof())
{
char ch;
infile >> ch;
// Useful to check that the read isn't the end of file
// - this stops an extra character being output at the end of the loop
if (!infile.eof())
{
cout << ch << endl;
}
}
system("pause");
}
#包括
#包括
使用名称空间std;
int main()
{
ifstream-infle(“input.txt”);
如果(!infle)
{
cout noskipws;
而(!infle.eof())
{
char ch;
填充>>ch;
//用于检查读取是否不是文件的结尾
//-这将在循环结束时停止输出额外字符
如果(!infle.eof())
{
cout将ch
的类型更改为std::string
,这样>
将读取单词。将ch
的类型更改为std::string
>
将读取单词。将ch
的类型更改为std::string
将读取单词。更改c的类型h
到std::string
因此>
将读取单词
我现在希望能够阅读整个单词,而不是字符,然后希望将每个单词存储到一个数组中,但我甚至不知道如何阅读整个单词
我现在希望能够阅读整个单词,而不是字符,然后希望将每个单词存储到一个数组中,但我甚至不知道如何阅读整个单词
我现在希望能够阅读整个单词,而不是字符,然后希望将每个单词存储到一个数组中,但我甚至不知道如何阅读整个单词
我现在希望能够阅读整个单词,而不是字符,然后希望将每个单词存储到一个数组中,但我甚至不知道如何阅读整个单词
使用
而不是
char ch;
infile >> ch;
使用
而不是
char ch;
infile >> ch;
使用
而不是
char ch;
infile >> ch;
使用
而不是
char ch;
infile >> ch;
不要将>
变成字符
你可以将>
变成std::string
请阅读有关此语句的链接:不要将>
变成字符
你可以将>
变成std::string
请阅读有关此语句的链接:不要将>
变成字符
您可以将>
转换成std::string
请阅读有关此语句的链接:您可以将>
转换成std::string
请阅读有关此语句的链接: