简而言之,我真的很纠结语法,有人可以帮助我解决这个问题
In short I really struggle with syntax, can somebody help me fix this?
所以我需要在文件中读取,然后使用数组为每次字符出现创建字数统计和字符数统计。 每个单词都以空格、逗号、句点等结尾。 此外,我还需要放置一个 tolower 和一个方程,以使用 x-'a' 函数或类似的东西将字母设置为正确的数组。
来自 puTTy 的错误列表(我知道蹩脚的程序,但这是必需的)
project8.cpp: 在函数 âint main()â
: Project8.cpp:17:错误:未在此范围内
声明"文件1" Project8.cpp:18:错误:预期"在一段时间
之前" Project8.cpp:36:错误:输入结束时的预期
#include <iostream>
#include <string>
using namespace std;
int in_word = false;
int word_count = 0;
char ch;
char low_case;
int char_count[26];
int i;
int main()
{
for (i=0; i<26; i++)
char_count[i]=0;
cin.get(file1.txt)
while('n' !=(ch=cin.get(file1.txt)))
{
if (' ' == ch || 'n' == ch || 't' == ch)
in_word = false;
else if (in_word == false)
{
in_word=true;
word_count++;
}
else low_case=tolower(ch);
char_count[int(low_case)-int('a')]++;
}
cout << file1.txt;
cout << words << " words" << endl;
for (i=0; i<26; i++)
if(count[i] !=0)
cout << count[i] << " " << char(i+'a') << endl;
}
第一个问题是你没有声明file1
.目前还不清楚file1.txt
的真正含义:它的编写方式,它似乎是一个类型的对象,其成员称为,txt
类型为 char*
或 char[N]
(具有常量N
)。从外观上看,您实际上想打开一个名为 file1.txt
的文件。这看起来像这样:
std::ifstream in("file1.txt");
之后,您当然会使用 in
而不是 std::cin
从文件中读取。例如,您可以使用
for (char c; in.get(c); ) {
// ...
}
读取文件的每个字符并对其进行适当处理。
让我们玩编译器吧!
不能将变量命名file1.txt
,请将其命名为file1
另外,您忘记了行尾的分号;
,所以
cin.get(file1.txt)
应该是
cin.get(file1);
我不太知道你在哪里定义这个变量,所以你可能缺少一个声明,
比如const char* file1="file1.txt";
此外,您在此处的 for 循环之后开始尝试访问一些变量count
:
count[i]
你的意思是使用char_count
吗?
相关文章:
- C++ DLL 运行时错误"abc.dll is not a valid WIN32 application" 。请帮助解决这个问题
- 需要帮助解决内存泄漏
- 任何熟悉Codecademy C++/程序的人都可以帮助解决菜鸟问题吗?
- 你能帮助解决这个错误吗?(g++原型与类中的任何原型都不匹配)
- 需要帮助解决C++中扫描仪/词法分析器代码部分中的分割错误
- 需要帮助解决错误 C2664
- 需要帮助解决稀疏 ax=b
- 与操作员'<<'不匹配 有人可以帮助解决无效功能错误吗?[C++]
- 需要帮助解决特征数组并行构造中的数据争用
- 需要帮助解决链接器错误LNK2001 Visual Studio 2010
- 需要帮助解决C++引擎/框架构建中的链接器错误
- 需要帮助解决内存泄漏错误
- 需要帮助解决LNK1104:使用 VS2010 构建 openCV 时无法打开文件'opencv_core231.obj' helloworld
- 需要帮助解决我的程序中的小问题
- 需要帮助解决库冲突
- 帮助解决编程挑战
- 帮助解决设计问题
- 帮助解决 c 错误
- 需要帮助解决一些错误消息
- 帮助解决这个问题