小编kay*_*cee的帖子

错误C2146:语法错误:缺少';' 在标识符之前

我无法摆脱这些错误...我检查到处都是分号...代码很简单:错误将我带到了article.h中的"字符串名称"定义...

main.cpp中

#include <iostream>
#include <fstream>
#include <vector>
#include <string>

using namespace std;

#include "article.h"

int main()
{
 string si;
 char article[128];
 vector<Article> articles;
 ifstream file;


 file.open("input.txt",ifstream::in);

 while(!file.eof())
 {
  file.getline(article,128);
  articles.push_back(Article(article));

 }

 file.close();

 while(1);
 return(1);
}
Run Code Online (Sandbox Code Playgroud)

article.h:

#ifndef Article_H
#define Article_H

class Article
{
public:
 int year;
 string name;

 Article(char *i_name);
};

#endif
Run Code Online (Sandbox Code Playgroud)

c++

8
推荐指数
1
解决办法
3万
查看次数

致命错误LNK1104:无法打开文件'libboost_regex-vc90-mt-gd-1_42.lib'

我正在尝试在我的程序中使用boost regex问题是我得到这个错误...我做的唯一安装步骤是将"C:\ Program Files\boost\boost_1_42"添加到其他包含目录中...

我正在使用VS2008 ......

试图实现这个:

#include <iostream>
#include <string>
#include <boost/regex.hpp>

using namespace std;

int main( ) {

   std::string s, sre;
   boost::regex re;
   boost::cmatch matches;

   while(true)
   {
      cout << "Expression: ";
      cin >> sre;
      if (sre == "quit")
      {
         break;
      }

      cout << "String:     ";
      cin >> s;

      try
      {
         // Assignment and construction initialize the FSM used
         // for regexp parsing
         re = sre;
      }
      catch (boost::regex_error& e)
      {
         cout << sre << " is not a …
Run Code Online (Sandbox Code Playgroud)

c++ boost-regex

7
推荐指数
1
解决办法
2万
查看次数

访问模板中的foreignKey

好吧,它很安静简单.2个具有ManyToMany关系的模型:

class Artist(models.Model):
   name = models.CharField(max_length=100, unique=True)
   slug = models.SlugField(max_length=100, unique=True,
            help_text='Uniq value for artist page URL, created from name')
   birth_name = models.CharField(max_length=100, blank=True)


class Song(models.Model):
   title = models.CharField(max_length=255)  
   slug = models.SlugField(max_length=255, unique=True,
            help_text='Unique value for product page URL, create from name.')
   youtube_link = models.URLField(blank=False)
   artists = models.ManyToManyField(Artist)
Run Code Online (Sandbox Code Playgroud)

我的观点是为了显示最新的5首歌曲:

def songs(request, template_name="artists/songs.html"):
   song_list = Song.objects.all().order_by('-created_at')[:5]
   return render_to_response(template_name, locals(),
                          context_instance=RequestContext(request))
Run Code Online (Sandbox Code Playgroud)

问题出在模板中...我想显示艺术家的名字,但我真的不知道怎么做,我试过:

{% for song in song_list %}
    {{ artists__name }} - {{ song.title }} 
{% endfor %}  
Run Code Online (Sandbox Code Playgroud)

非常感谢任何帮助!

django django-templates django-models

4
推荐指数
1
解决办法
1491
查看次数

c ++分配内存问题

我在c ++中分配内存时遇到了一个奇怪的问题我正在创建一个缓冲区并将文件内容读入其中.问题是分配是不正确的,并且在打印结束时有奇怪的字符......文件的内容是"你好"......我坐了几个小时......可能是什么问题?:(

void main()
{
 FILE *fp;
 char *buffer;
 long file_size;
 size_t result;

 fp = fopen("input.txt","r");
 if (fp == NULL) { fputs("File Error",stderr); exit(1); }

 //get file size
 fseek(fp, 0, SEEK_END);
 file_size = ftell(fp);
 rewind(fp);

 //allocate memory to contain the whole file size
 buffer = new char[file_size];

 if (buffer == NULL) { fputs("Cannot allocate memory space",stderr); exit(2); }

 //copy the file into the buffer
 result = fread(buffer, 1, file_size, fp);
 if (result != file_size) { fputs("Reading error",stderr); exit(3); }

 cout<<buffer; …
Run Code Online (Sandbox Code Playgroud)

c++

0
推荐指数
1
解决办法
809
查看次数