【发布时间】:2015-10-13 23:57:31
【问题描述】:
在我的项目中,我正在读取一个程序集文件(现在很小,仅用于测试)。我想看看我正在阅读的内容是否是标签(我相信我的代码很好)。如果它是一个标签,我会逐个字符地获取标签的全名,然后按索引将其分配给字符串索引,以便我可以获取标签的全名以供以后使用。出于某种原因,当我计算我的标签时,它只是给了我第一个字符而不是整个字符串。我相信问题出在“cout
#include <iostream>
#include <fstream>
#include <string>
#include <map>
using namespace std;
int main(int argc, char* argv[]) {
int counter = 0;
char x = ' ';
string myFileString = " ";
string label = " ";
if (argc < 2) {
cout << "Error: Not enough arguments in the command line!" << endl;
}
else {
ifstream myFile(argv[1]);
if (!(myFile.is_open())) {
cout << "Error: Could not open the file!" << endl;
}
else {
while (!(myFile.eof())) {
getline(myFile, myFileString);
// Does not have a label
if (myFileString[0] == ' ') {
cout << "No label here!" << endl;
}
// Has a label
else {
while (myFileString[counter] != ' ') {
label[counter] = myFileString[counter];
counter++;
}
cout << label << endl;
counter = 0;
}
}
}
}
cin.get();
cout << endl;
}
【问题讨论】:
标签: c++ string visual-studio