- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在拉取一个文本文件 - 它将由用户输入目前它只是从 C:\Dump\test.txt 中提取我想重新排列所述文件中的单词
这是我目前的情况
static string revFunc(string a)
{
ifstream inp;
inp.open(a, std::ios::in);
string lines;
while(getline(inp, lines)){
istringstream iss(lines);
string outstr;
string word;
iss >> outstr;
if (inp >> word){
outstr = word + ' ' + outstr + ' ';
cout << outstr;
}
}return 0;
}
字符串a是硬盘上文件的路径这将向后解析 2 行测试文件中有 ~13 行
这是来自 int main()
int main(){
string file;
int words = 0;
int lines = 0;
int choice;
system("cls");
cout << "Enter Filename: " << endl;
file = "C:\\Dump\\test.txt";
cout << file;
//cin >> file;
cout <<"MENU"<<endl;
cout <<"----------------------------------" << endl;
cout << "1. Count Words" << endl;
cout << "2. Count Lines" << endl;
cout << "3. Index Words" << endl;
cout << "4. Average Length of Words" << endl;
cout << "5. Print Text File to Screen" << endl;
cout <<"----------------------------------" << endl;
cout << "??: ";
cin >> choice;
switch(choice){
case 1: cout << "Words: " << wordFunc(file) << endl;
system("PAUSE");
break;
case 2: cout << "Lines: " << lineFunc(file, lines) << endl;
system("PAUSE");
break;
case 3: indexFunc(file);
system("PAUSE");
break;
case 4: cout << "Average Length: " << avgWordFunc(file) << endl;
system("PAUSE");
break;
case 5: printStrFunc(file);
cout <<endl;
system("PAUSE");
break;
case 6: revFunc(file);
cout << endl;
system("PAUSE");
break;
}
return 0;
}
然后程序中止 - 我确定是由于错误的编码 :)感谢任何指出我荒谬错误的帮助
最佳答案
你说你的 refFunc
返回一个 string
,但返回值是 0
(一个 int
,不是字符串
).
这将导致问题,因为程序尝试使用字符串对象,并发现“垃圾”(已分配以预期字符串但未填充字符串的正确位)。
要修复,您需要将返回值 type 更改为 int
或将返回值 value 更改为有效字符串(例如 ""
).
或者,如果您不使用返回值(如示例中的情况),则可以将返回类型更改为 void
。在这种情况下,只使用return;
(注意:return 后没有值),或者你可以把整个return 语句都去掉;
注意:为防止将来出现此类错误,请将编译器配置为使用最大警告设置进行编译,并可能将警告转化为错误。这将防止您在编译器至少没有告诉您您正在做某事(很可能)不正确的情况下编译您的程序
注意:即使是暂停应用程序,也不要养成使用 system()
的习惯。它依赖于平台,并且会带来安全风险(尽管我认为您暂时不会担心)
关于c++ - 字符串重排 C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9940803/
这是我对DOM和浏览器如何工作的幼稚理解 每当DOM中的某些内容(真实dom)更改时,浏览器就会重新绘制或重排该DOM。因此,用更简单的术语来说,每次DOM更改时,浏览器都需要重新计算CSS,进行布局
我有这个 HTML 代码 http://jsfiddle.net/tbpqT/ Block A Block B 当屏幕尺寸变得
所有问题都与.net Framework 2.0中的.net项目dll有关,该dll将自身公开为COM。 1)如果我们在源代码(typelib,类,接口)中未指定任何GUID,那么谁在生成GUID?编
我正在使用 StaggeredGridLayoutManager 并获得接近我想要的东西。我有一个水平交错的 2 行网格,其中一些项目是 1 行的高度,而其他项目跨越两行。我希望单行高项目堆叠起来,我
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭 3 年前。
我是一名优秀的程序员,十分优秀!