English 中文(简体)
C++ 读到文本中,读到Array of vec4
原标题:C++ Reading in Text file to Array of vec4

我知道那里存在几个文本与通知问题,但我很难把这些问题同起来。

在C++上我并不好,但需要将其用于我的开放Gl方案拟定工作。

Basically I have made an array of vec4 s (vec4 is just 4 "points" for a coord system), and then I printed them out to a text file. The file reads like so (I eliminated the last point because it is ALWAYS 1 and I figured I could add it in when reading the text file later):

( 0.26, 0385, 0.48 )

( 0.27, 0386, 0.47 )

( 0.28, 0387, 0.46 )

( 0.29, 0388, 0.45 )

因此,每一行各有一行;

现在我想读一下这一文本,把它重新编成一阵。 避免这种情况的最容易的方法是什么(、、、和)? 如果能够消除这些不想要的特性,我也许会写出大量长篇大事,但那将是相当低效率的,而且肯定会有人在那里穿过更衣的手法。

任何建议? 帮助?

感谢!

最佳回答

如果这种格式绝对肯定如此,那么你就能够做一根na子,根植于标准线投入。

#include <fstream>   // for std::ifstream
#include <sstream>   // for std::istringstream
#include <string>    // for std::string and std::getline
#include <vector>    // for std::vector
#include <tuple>     // for std::tuple

int main()
{
    std::ifstream infile("thefile.txt");
    std::string line;

    std::vector<std::tuple<double, double, double, double>> points;

    while (std::getline(infile, line))
    {
        std::istringstream iss(line);
        double d1, d2, d3;
        char c1, c2, c3;

        if ((iss >> c1 >> d1 >> c2 >> d2 >> c3 >> d3) &&
            (c1 ==  (  && c2 ==  ,  && c3 ==  , )        )
        {
            points.emplace_back(d1, d2, d3, 1.0);
        }
        else
        {
            // error processing this line
        }
    }
}

可能产生的两个错误是:line。 n n required required required required 或limit de . . . . . . 这取决于你如何处理这一问题。

如果你需要更大的灵活性,你可以处理每一行“<条码>和>;regex>,或者你甚至可以写出一个象Boost这样更强大的普通子。 Qi(尽管这无疑是高技能的)。

问题回答

你们需要把这些内容读作说明。 因此,如果您阅读了一条线,你可以在此看看管功能,并选择最适合你的东西:

如果你想要的话,你可以使用<代码>replace功能,将“、”和“”改为“”。 通过这样做,你将掌握按空间分列的3项价值观。





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签