我有一个文本文件中的数字一些负面的,都包含小数,我设法读取它们并将它们转换为整数来显示;读int作为独立的数字
for (int i = 0; i < 1; i++)
{
std::string str = &(cmemblock[0]); //cmemblock is the .txt file
std::istringstream iss(str);
std::vector<int> numbers;
int number;
while (iss >> number) {
numbers.push_back(number); // collect inputs
cout << number << endl; //Displays Stored Value
}
if (!iss.eof()) {
cout << "Blank Space"<<endl; //Error message to detect blank space
}
}
我需要创建一个循环读取每个每一个字符,例如,如果第一行是帮助“-0.009876”,每个值应单独阅读,“ - ”,“0”“”。等等。其原因是因为数字要用莫尔斯电码代表,因为它已经在数组中建立起来了,所以我需要个别号码来将每个数字分配给它指定的莫尔斯电码。
为什么不使用字符串的'[]'运算符循环/迭代字符串的每个单独的字符? – TypeIA
你是否期待数字格式不同?如10E + 3? –
@R Sahu不,它应该是整数 – NoobProgrammer