如何将字符串转换为数字
how can I get string to number?
我正在研究数据收集,并试图扫描标题并将其转换为实数,使用"sscanf",但它没有像我期望的那样给我数字,编写的"拆分函数"正在帮助我拆分字符串向量:
#include <iostream> // std::cout
#include <string> // std::string, std::stod
int main() {
string fn = "ch-683-mhz-8000.0-ksps-2016-06-20-17.24.19-utc.dat";
vector<string> v;
int f0, fs;
split(fn, '-', v);
for (int i = 0; i < v.size(); ++i) {
cout << i << " " << v[i] << 'n';
}
for(unsigned i=1; i < v.size(); i++){
if(v[i] == "mhz"){
std::sscanf(v[i-1], &f0);
int ret = sscanf(v[i-1], &f0);
cout << v[i-1] ;
}
}
return 0;
}
的"向量v"将给我的结果:683兆赫8000.0过度增殖20160620.17.24.19utc.dat
和我想把683和8000转换成实数,但我收到了错误,即使我试图从论坛做一些搜索:
Description Resource Path Location Type
'resize' is ambiguous '
Candidates are:
void resize(unsigned long int, std::complex<float>)
' fft.hpp /test2/src line 186 Semantic Error
recipe for target 'src/test2.o' failed subdir.mk /test2/Debug/src line 18 C/C++ Problem
'resize' is ambiguous '
Candidates are:
void resize(unsigned long int, std::complex<float>)
' fft.hpp /test2/src line 251 Semantic Error
cannot convert ‘std::__cxx11::basic_string<char>’ to ‘const char*’ for argument ‘1’ to ‘int sscanf(const char*, const char*, ...)’ test2.cpp /test2/src line 495 C/C++ Problem
cannot convert ‘std::__cxx11::basic_string<char>’ to ‘const char*’ for argument ‘1’ to ‘int sscanf(const char*, const char*, ...)’ test2.cpp /test2/src line 494 C/C++ Problem
Invalid arguments '
Candidates are:
int sscanf(const char *, const char *, ...)
' test2.cpp /test2/src line 494 Semantic Error
Invalid arguments '
Candidates are:
int sscanf(const char *, const char *, ...)
' test2.cpp /test2/src line 495 Semantic Error
make: *** [src/test2.o] Error 1 test2 C/C++ Problem
有人能帮忙吗?
int main()
{
string fn = "ch-683-mhz-8000.0-ksps-2016-06-20-17.24.19-utc.dat";
string szt1;
for (int i = 0; i < 15; i++)
{
szt1 = szt1 + fn[i];
}
int n1;
int n2;
string szn1;
string szn2;
for (int i = 3; i < szt1.length(); i++)
{
if (i < 6)
{
szn1 = szn1 + szt1[i];
}
}
for (int i = 11; i < szt1.length(); i++)
{
szn2 = szn2 + szt1[i];
}
n1 = atoi(szn1.c_str());
n2 = atoi(szn2.c_str());
cout << n1 << endl;
cout << n2 << endl;
return 0;
}
相关文章:
- 将数字转换为字母(例如:123 转换为一二三)
- 将数字转换为单词
- 使用if-else将数字转换为单词
- 将数字转换为填充字符串
- 编译时间文本到数字转换 (atoi)
- 在 c++ 中将数字转换为矢量数组的函数
- 奇怪的数字转换C++
- 用C++将浮点数字转换为本地化字符串
- 如何将ASCII数字转换为从文件中提取的整数
- 检查字符串是否是数字,然后将该数字转换为 int?
- 将 MPFR 数字转换为字符串并返回
- 如何将数字转换为整数向量?
- 如何在C++中将数字转换为链表
- 如何将字符串中的多个数字转换为整数
- 有问题将数字转换为罗马数字
- 这个给定的代码应该将给定的数字转换为尽可能滞后的数字,no.by 用 9.It 替换合适的数字是行不通的
- 将两位数字转换为低内存表示的最快方法
- 视觉 如何将混合的字母和数字转换为仅字母?C++
- 如何在 c++ 中将十六进制数字转换为字符
- 如何将字符串数字转换为各个数字的整数数组